Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Help: f (repeat) modifier, and histsubstpattern + :s/l/r/ modifier escaping of [{()}]



On Wed, Aug 16, 2023 at 8:19 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> > 2. Why doesn't the replacement seem to happen to each subsequent
> > result of a former replacement?
>
> Because there's a bug.

Proof of bug / concept of fix.  This might eat a lot of heap so
something more detailed is probably needed, so I'm not going to bother
to protect this from gmail line wrapping etc.

diff --git a/Src/subst.c b/Src/subst.c
index 14947ae36..7b866e638 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -4539,7 +4539,8 @@ modify(char **str, char **ptr, int inbrace)
             case 'S':
             hsubpatopt = (c == 'S');
             if (hsubl && hsubr)
-                subst(&copy, hsubl, hsubr, gbal, hsubpatopt);
+                subst(&copy, dupstring(hsubl), dupstring(hsubr),
+                  gbal, hsubpatopt);
             break;
             case 'q':
             copy = quotestring(copy, QT_BACKSLASH_SHOWNULL);
@@ -4627,7 +4628,8 @@ modify(char **str, char **ptr, int inbrace)
         case 'S':
             hsubpatopt = (c == 'S');
             if (hsubl && hsubr)
-            subst(str, hsubl, hsubr, gbal, hsubpatopt);
+            subst(str, dupstring(hsubl), dupstring(hsubr),
+                  gbal, hsubpatopt);
             break;
         case 'q':
             *str = quotestring(*str, QT_BACKSLASH);




Messages sorted by: Reverse Date, Date, Thread, Author