Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [bug] $scalar[(pws[\0])1] or $scalar[(pws[á])1] doesn't work
> 2022/11/13 17:14, Stephane Chazelas <stephane@xxxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author