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 Thu, Aug 17, 2023 at 4:09 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> Proof of bug / concept of fix.  This might eat a lot of heap so
> something more detailed is probably needed

There doesn't seem to be any better approach without actually invoking
pushheap/popheap which is likely overkill for most cases of this, so
I'm just going to commit users/29160.

Here's a test suite patch to go with it.

> 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);

diff --git a/Test/E01options.ztst b/Test/E01options.ztst
index 83f0371a1..363846f5c 100644
--- a/Test/E01options.ztst
+++ b/Test/E01options.ztst
@@ -561,12 +561,14 @@
   foo=(one.c two.c three.c)
   print ${foo:s/#%(#b)t(*).c/T${match[1]}.X/}
   print *(#q:s/#(#b)tmp(*e)/'scrunchy${match[1]}'/)
+  print ${${:-"left[({})]over"}:fs/(\\{\\}|\\(\\)|\\[\\])//}
   unsetopt histsubstpattern
 0:HIST_SUBST_PATTERN option
 >TINGcd TINGfile1 TINGfile2 homedir
 >THUMPcd THUMPfile1 THUMPfile2
 >one.c Two.X Three.X
 >homedir scrunchyfile1 scrunchyfile2 tmpcd
+>leftover

   setopt ignorebraces
   echo X{a,b}Y




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