From: Peter Stephenson <p.stephenson@samsung.com>
To: <zsh-workers@zsh.org>
Subject: Re: BUG: small posix glitch in ${x%*}
Date: Tue, 10 Dec 2019 10:48:24 +0000 [thread overview]
Message-ID: <1575974904.4447.1.camel@samsung.com> (raw)
In-Reply-To: <CAOFpr6BPmd6V8NZOVdG3JMqwbMBjVEi_7cr4AEFwAHfhgXUSRg@mail.gmail.com>
On Mon, 2019-12-09 at 22:07 +0000, Jan Grant wrote:
> As I read the spec, the smallest suffix that can match * is the null
> string; so
>
> x=123; echo ${x%*}
>
> should output "123". Zsh (as of 5.7.1) drops the last character.
>
> (The behaviour for prefixes is correct.)
Yes, that's right --- there are already some age-old icky special cases
for this in some places but not this one. So a bit of copy and paste...
pws
diff --git a/Src/glob.c b/Src/glob.c
index 92fd64e7c..674563c8f 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -2909,6 +2909,12 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr,
*/
mb_charinit();
tmatch = NULL;
+ set_pat_start(p, l);
+ if (pattrylen(p, send, 0, 0, &patstralloc, umltot) &&
+ !--n) {
+ *sp = get_match_ret(&imd, umltot, umltot);
+ return 1;
+ }
for (ioff = 0, t = s, umlen = umltot; t < send; ioff++) {
set_pat_start(p, t-s);
if (pattrylen(p, t, umlen, 0, &patstralloc, ioff))
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index b6e85a9fe..c91af1a9c 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -2534,3 +2534,26 @@ F:behavior, see http://austingroupbugs.net/view.php?id=888
0:Global variables are not trashed by "foo=bar builtin" (regression test)
>function-value
>global-value
+
+ foo=pws
+ print ${foo%*}
+0:Smallest match at end can match zero-length string
+>pws
+
+ foo=pws
+ print ${foo%?}
+0:Smallest match at end with a character always matches one
+>pw
+
+ setopt extendedglob
+ foo=pws
+ print ${foo%s#}
+ print ${foo%%s#}
+0:Smallest / largest match with non-trivial closure
+>pws
+>pw
+
+ foo=pws
+ print ${foo%%*}
+0:Largest match at end matches entire string
+>
prev parent reply other threads:[~2019-12-10 10:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20191210014119eucas1p155aa663c9f726ba5ca07a37c54829bec@eucas1p1.samsung.com>
2019-12-09 22:07 ` Jan Grant
2019-12-10 10:48 ` Peter Stephenson [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=1575974904.4447.1.camel@samsung.com \
--to=p.stephenson@samsung.com \
--cc=zsh-workers@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).