Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: #% anchoring doesn't work with (S)
- X-seq: zsh-workers 51350
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: #% anchoring doesn't work with (S)
- Date: Thu, 2 Feb 2023 10:49:59 +0000 (GMT)
- Archived-at: <https://zsh.org/workers/51350>
- Importance: Normal
- In-reply-to: <CAKc7PVBi-_jW2UZkOaxpOqUG=V+DS8sU814nVp4Yj7Su28Kqpg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAKc7PVA=Beup8-GyjpxCst0=Ne_-v1yjYqn46YuRMTRuvTpteg@mail.gmail.com> <CAKc7PVBi-_jW2UZkOaxpOqUG=V+DS8sU814nVp4Yj7Su28Kqpg@mail.gmail.com>
> On 02/02/2023 08:31 Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
> Could the bugbe fixed? It already makes #% pretty much unusable for a backward compatible software, yet in say 4 years this would be changed, if the bug would be fixed today
>
> On Mon, 30 Jan 2023 at 12:32, Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
> > INPUT=ABC; INPUT=${(S)INPUT//#%((#b)(*))/°match°}; print $match
> > #no output
It's a confusing combination of options but it looks like it's trying to do a shortest
match as if with a ${param#head} or ${param%tail} and so bailing out early when it's
found a substring. This obviously doesn't work when we're anchoring at both the
start and the end, so tell it to do a longest match in that case.
We could probably do with some more tests with the #% combination, there aren't all
that many, so other oddities might be sneaking through.
pws
diff --git a/Src/subst.c b/Src/subst.c
index 4ad9fee1a..3dd920e87 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -2926,6 +2926,9 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
*/
if (!(flags & (SUB_MATCH|SUB_REST|SUB_BIND|SUB_EIND|SUB_LEN)))
flags |= SUB_REST;
+ /* If matching at start and end, don't stop early */
+ if ((flags & (SUB_START|SUB_END)) == (SUB_START|SUB_END))
+ flags |= SUB_LONG;
/*
* With ":" treat a value as unset if the variable is set but
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index a11652d1e..7990c2958 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -2307,6 +2307,13 @@ F:behavior, see http://austingroupbugs.net/view.php?id=888
>x
>y
+ a="string"
+ print ${(S)a//#%((#b)(*))/different}
+ print $match[1]
+0:Fully anchored string must be fully searched
+>different
+>string
+
my_width=6
my_index=1
my_options=Option1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author