From: "Jun. T" <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: [bug] $scalar[(pws[\0])1] or $scalar[(pws[á])1] doesn't work
Date: Tue, 29 Nov 2022 00:47:44 +0900 [thread overview]
Message-ID: <F91D483C-2767-436F-9919-9326BCDFDE9A@kba.biglobe.ne.jp> (raw)
In-Reply-To: <20221113081452.bk7zdnbc6qvqjxef@chazelas.org>
> 2022/11/13 17:14, Stephane Chazelas <stephane@chazelas.org> wrote:
>
> $ a=$'foo\0bar'
> $ echo $a[(pws[\0])1]
> f
>
> Expected "foo".
>
> It seems that's some missing metafication
Yes. The following seems to work (simple test is included)
diff --git a/Src/params.c b/Src/params.c
index 27ea82298..f1fe38955 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -1262,7 +1262,6 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
/* first parse any subscription flags */
if (v->pm && (*s == '(' || *s == Inpar)) {
int escapes = 0;
- int waste;
for (s++; *s != ')' && *s != Outpar && s != *str; s++) {
switch (*s) {
case 'r':
@@ -1339,8 +1338,13 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
sav = *t;
*t = '\0';
s += arglen;
- sep = escapes ? getkeystring(s, &waste, GETKEYS_SEP, NULL)
- : dupstring(s);
+ if (escapes) {
+ int len;
+ sep = getkeystring(s, &len, GETKEYS_SEP, NULL);
+ sep = metafy(sep, len, META_HREALLOC);
+ }
+ else
+ sep = dupstring(s);
*t = sav;
s = t + arglen - 1;
break;
diff --git a/Test/D06subscript.ztst b/Test/D06subscript.ztst
index adbd398c4..21127e641 100644
--- a/Test/D06subscript.ztst
+++ b/Test/D06subscript.ztst
@@ -294,3 +294,8 @@ F:Regression test for workers/42297
[[ ${a[$i]} = ${a[i]} ]]
0f:Math evaluation of commas in array subscripts
F:In math, (($i)) should be the same as ((i)), see workers/47748.
+
+ string=$'foo\0bar'
+ echo ${string[(pws:\0:)1]}
+0:Word splitting by NUL
+>foo
prev parent reply other threads:[~2022-11-28 15:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-13 8:14 Stephane Chazelas
2022-11-18 12:25 ` Stephane Chazelas
2022-11-28 15:50 ` Jun. T
2022-11-28 23:57 ` Jun T
2022-11-28 15:47 ` Jun. T [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=F91D483C-2767-436F-9919-9326BCDFDE9A@kba.biglobe.ne.jp \
--to=takimoto-j@kba.biglobe.ne.jp \
--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).