]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
transform: fix replacement of particular pattern instance
authorSergey Poznyakoff <gray@gnu.org>
Sat, 28 Aug 2021 06:13:05 +0000 (09:13 +0300)
committerSergey Poznyakoff <gray@gnu.org>
Sat, 28 Aug 2021 06:57:26 +0000 (09:57 +0300)
This fixes handling of expressions like 's/s/@/2'

Fix suggested by Anthony Heading.

* src/transform.c (_single_transform_name_to_obstack): Avoid duplicating
initial prefix if replace is not needed.

src/transform.c

index 2b60235392cbfc9e65a7eb8f88e6bcc0bb1c79d6..2cc927e841b4827e1bf4bd69eb50d8200cbe384e 100644 (file)
@@ -493,9 +493,6 @@ _single_transform_name_to_obstack (struct transform *tf, char *input)
 
          disp = rmp[0].rm_eo;
 
-         if (rmp[0].rm_so)
-           obstack_grow (&stk, input, rmp[0].rm_so);
-
          nmatches++;
          if (tf->match_number && nmatches < tf->match_number)
            {
@@ -504,6 +501,9 @@ _single_transform_name_to_obstack (struct transform *tf, char *input)
              continue;
            }
 
+         if (rmp[0].rm_so)
+           obstack_grow (&stk, input, rmp[0].rm_so);
+
          for (segm = tf->repl_head; segm; segm = segm->next)
            {
              switch (segm->type)