summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stephenson <p.stephenson@samsung.com>2020-06-22 12:06:43 +0100
committerPeter Stephenson <p.stephenson@samsung.com>2020-06-23 12:17:32 +0100
commitaf1c009c3ea97cb4ec79b54c8b208198230e3ffb (patch)
treec970cd9ebeacc2882516f27028ab20be9af65b7b
parentae0129b49f9f1b624fb4b067f6f1ef6757a24fd2 (diff)
downloadzsh-af1c009c3ea97cb4ec79b54c8b208198230e3ffb.tar.gz
zsh-af1c009c3ea97cb4ec79b54c8b208198230e3ffb.zip
46079: Ignore double quotes in math expressions.
Treat as white space. This is required for compatibility and previously had no use in zsh as it generated an error.
-rw-r--r--ChangeLog5
-rw-r--r--Src/math.c2
-rw-r--r--Test/C01arith.ztst10
3 files changed, 15 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index bf139ed0c..11829e3a6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-06-22 Peter Stephenson <p.stephenson@samsung.com>
+
+ * 46079: Src/math.c, Test/C01arith.ztst: Ignore double quotes in
+ math expression: treat as white space.
+
2020-06-22 Manuel Jacob <me@manueljacob.de>
* 46091: Doc/Zsh/contrib.yo,
diff --git a/Src/math.c b/Src/math.c
index 905b910ec..b57ba42d4 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -831,6 +831,8 @@ zzlex(void)
case ' ': /* Fall through! */
case '\t':
case '\n':
+ case '"': /* POSIX says ignore these */
+ case Dnull:
break;
default:
if (idigit(*--ptr) || *ptr == '.')
diff --git a/Test/C01arith.ztst b/Test/C01arith.ztst
index 419f45292..d0092fefa 100644
--- a/Test/C01arith.ztst
+++ b/Test/C01arith.ztst
@@ -180,9 +180,10 @@
1:bases beyond 36 don't work
?(eval):1: invalid base (must be 2 to 36 inclusive): 37
+ fail=39
print $(( 3 + "fail" ))
-1:parse failure in arithmetic
-?(eval):1: bad math expression: operand expected at `"fail" '
+0:Double quotes are not treated specially in arithmetic
+>42
alias 3=echo
print $(( 3 + "OK"); echo "Worked")
@@ -487,3 +488,8 @@
let noexist==0 )
1:Arithmetic, NO_UNSET part 3
?(eval):2: noexist: parameter not set
+
+ print $(( "6+2" / "1+3" ))
+0:Double quotes are not treated specially in arithmetic (POSIX)
+# and do not do grouping! this is 6 + (2/1) + 3
+>11