zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Andy Kluger <andykluger@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: Help: f (repeat) modifier, and histsubstpattern + :s/l/r/ modifier escaping of [{()}]
Date: Thu, 17 Aug 2023 16:09:16 -0700	[thread overview]
Message-ID: <CAH+w=7Yv_tyBKLo1PuoeDB-YkWwpGh5d_hZODyTH7J0mgD3RNg@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7Y+zos=sRfAv2769iJEzazHRfT4u6v+3B3mGoxy8Yv0-w@mail.gmail.com>

On Wed, Aug 16, 2023 at 8:19 PM Bart Schaefer <schaefer@brasslantern.com> 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);


      reply	other threads:[~2023-08-17 23:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-16 18:32 Andy Kluger
2023-08-17  3:19 ` Bart Schaefer
2023-08-17 23:09   ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7Yv_tyBKLo1PuoeDB-YkWwpGh5d_hZODyTH7J0mgD3RNg@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=andykluger@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).