summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stephenson <p.stephenson@samsung.com>2023-01-16 11:10:02 +0000
committerPeter Stephenson <p.stephenson@samsung.com>2023-01-16 11:10:02 +0000
commit03292bceecba1ca39745f82fe37f321d08b138e4 (patch)
treebed61efea2f1732a1d294aeac6e8ea71c158dd00
parent857bc4343b9215bcf6ac2761cbdd0a11fcd4d010 (diff)
downloadzsh-03292bceecba1ca39745f82fe37f321d08b138e4.tar.gz
zsh-03292bceecba1ca39745f82fe37f321d08b138e4.zip
51278: make (i) subscript flag for zero-length string consistent
-rw-r--r--ChangeLog6
-rw-r--r--Src/params.c2
-rw-r--r--Test/D06subscript.ztst9
3 files changed, 16 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 23baf278b..69ea1ab53 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-01-16 Peter Stephenson <p.stephenson@samsung.com>
+
+ * 51278: Src/params.c, Test/D06subscript.ztst: result of (i)
+ subscript flag with zero-length string was inconsistent with
+ other cases.
+
2023-01-11 Oliver Kiddle <opk@zsh.org>
* 51297: Test/X04zlehighlight.ztst: update expected test results
diff --git a/Src/params.c b/Src/params.c
index 2e4a6eae2..6362b382c 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -1669,7 +1669,7 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
/* Searching characters */
int slen;
d = getstrvalue(v);
- if (!d || !*d)
+ if (!d)
return 0;
/*
* beg and len are character counts, not raw offsets.
diff --git a/Test/D06subscript.ztst b/Test/D06subscript.ztst
index 21127e641..57cdc027c 100644
--- a/Test/D06subscript.ztst
+++ b/Test/D06subscript.ztst
@@ -299,3 +299,12 @@ F:In math, (($i)) should be the same as ((i)), see workers/47748.
echo ${string[(pws:\0:)1]}
0:Word splitting by NUL
>foo
+
+ string="a"
+ print ${string[(i)x]}
+ string=""
+ print ${string[(i)x]}
+0:Can check off end of zero length string
+F:Regression test for inconsistency of failed (i) on zero-length string
+>2
+>1