bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-tar] Allow escaped delimiter in transform replace expression (with


From: Flavio Poletti
Subject: [Bug-tar] Allow escaped delimiter in transform replace expression (with patch)
Date: Tue, 19 Jan 2016 13:49:42 +0100

Hi! Thank you for tar and the work you do!

I got the following issue:

$ touch foo.bar
$ tar cvf /dev/null foo.bar --show-transformed-name --transform
's/foo.bar/some\/foo.bar/'
some\\/foo.bar
$ echo foo.bar | sed -e 's/foo.bar/some\/foo.bar/'
some/foo.bar

Hence, the substitution is not exactly working as in sed... the
escaping character is left before each occurrence of the delimiter
character. This is still present in the latest version available as of
today, i.e. 1.28.

There was a previous bug (with patch) reported about this issue:
http://lists.gnu.org/archive/html/bug-tar/2015-08/msg00010.html - the
patch there has a bug that "eats" a character.

Please find below the corrected patch to src/transform.c and a test
for this bug.

Thank you again,

    Flavio.


---- cut here ----
---
 src/transform.c   |   16 ++++++++++------
 tests/Makefile.am |    1 +
 tests/xform02.at  |   36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 6 deletions(-)
 create mode 100644 tests/xform02.at

diff --git a/src/transform.c b/src/transform.c
index cd9e27c..3484649 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -379,12 +379,16 @@ parse_transform_expr (const char *expr)

         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);
+          else
+            {
+          /* Try to be nice */
+          char buf[2];
+          buf[0] = '\\';
+          buf[1] = *cur;
+          add_literal_segment (tf, buf, buf + 2);
+            }
           cur++;
           break;
         }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6684d1d..0da9d4d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -215,6 +215,7 @@ TESTSUITE_AT = \
  version.at\
  xform-h.at\
  xform01.at\
+ xform02.at\
  star/gtarfail.at\
  star/gtarfail2.at\
  star/multi-fail.at\
diff --git a/tests/xform02.at b/tests/xform02.at
new file mode 100644
index 0000000..065b11f
--- /dev/null
+++ b/tests/xform02.at
@@ -0,0 +1,36 @@
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+
+# Test suite for GNU tar.
+# Copyright 2009-2010, 2013-2014 Free Software Foundation, Inc.
+
+# This file is part of GNU tar.
+
+# GNU tar is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# GNU tar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([transforming escaped delimiters on create])
+AT_KEYWORDS([transform xform delimiter])
+
+AT_TAR_CHECK([
+genfile --file file
+tar cvf /dev/null file \
+   --transform='s/file/other\/name/' \
+   --show-transformed-name
+],
+[0],
+[other/name
+])
+
+AT_CLEANUP
+
+# End of xform02.at
-- 
1.7.10.4
---- cut here ----



reply via email to

[Prev in Thread] Current Thread [Next in Thread]