[prev in list] [next in list] [prev in thread] [next in thread]
List: tar-bug
Subject: [Bug-tar] [PATCH] Allow escaped delimiter in transform replace expr.
From: Charles McGarvey <chazmcgarvey () brokenzipper ! com>
Date: 2015-08-11 23:14:31
Message-ID: E1ZPJ3c-0006ys-E1 () vulcan ! local
[Download RAW message or body]
I was surprised today to discover that you cannot escape a delimiter in the
replace expression of a --transform option. GNU tar treats the delimiter like
any other non-special character, causing a literal backslash to also be
inserted in the replacement before the delimiter. Is this a bug? If so, here
is a patch with a possible fix (though I'd need some help to write a test).
Example:
tar -x --transform='s/foo/bar\/baz/'
# expecting "foo" to be replaced with "bar/baz", but get "bar\/baz" instead
---
src/transform.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/transform.c b/src/transform.c
index cd9e27c..2fbcc64 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -378,13 +378,19 @@ parse_transform_expr (const char *expr)
break;
default:
- /* Try to be nice */
- {
- char buf[2];
- buf[0] = '\\';
- buf[1] = *cur;
- add_literal_segment (tf, buf, buf + 2);
- }
+ if (*cur == delim)
+ {
+ add_char_segment (tf, delim);
+ cur++;
+ }
+ else
+ {
+ /* Try to be nice */
+ char buf[2];
+ buf[0] = '\\';
+ buf[1] = *cur;
+ add_literal_segment (tf, buf, buf + 2);
+ }
cur++;
break;
}
--
2.5.0
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic