From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 20892 invoked from network); 19 Jun 2020 15:56:02 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 19 Jun 2020 15:56:02 -0000 Received: (qmail 25320 invoked by alias); 19 Jun 2020 15:55:56 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: Sender: zsh-workers@zsh.org X-Seq: 46079 Received: (qmail 20646 invoked by uid 1010); 19 Jun 2020 15:55:56 -0000 X-Qmail-Scanner-Diagnostics: from smtpq1.tb.ukmail.iss.as9143.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25842. spamassassin: 3.4.4. Clear:RC:0(212.54.57.96):SA:0(-2.7/5.0):. Processed in 3.598234 secs); 19 Jun 2020 15:55:56 -0000 X-Envelope-From: p.w.stephenson@ntlworld.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _mailcloud.virginmedia.com designates 212.54.57.96 as permitted sender) X-Env-Mailfrom: p.w.stephenson@ntlworld.com X-Env-Rcptto: zsh-workers@zsh.org X-SourceIP: 172.25.160.136 X-CNFS-Analysis: v=2.3 cv=M6LW1x4s c=1 sm=1 tr=0 a=4AIt8OzuWET5BS7mAkvERw==:117 a=KEnZaF_ea6UA:10 a=IkcTkHD0fZMA:10 a=DoY9bV0jb9AA:10 a=uZvujYp8AAAA:8 a=E-Gb0JTgYUO0UhiqANQA:9 a=QEXdDO2ut3YA:10 a=DkUxev3uDU8A:10 a=SLzB8X_8jTLwj6mN0q5r:22 X-Authenticated-Sender: p.w.stephenson@ntlworld.com Date: Fri, 19 Jun 2020 16:55:13 +0100 (BST) From: Peter Stephenson To: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= , Mikael Magnusson Cc: Bart Schaefer , zsh-workers@zsh.org Message-ID: <599829801.251104.1592582113228@mail2.virginmedia.com> In-Reply-To: References: <17B9983F-268E-469C-9506-D5333528A805@larryv.me> Subject: Re: bad math expression: illegal character: " MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 Importance: Medium X-Mailer: Open-Xchange Mailer v7.8.4-Rev70 X-Originating-IP: 165.225.81.56 X-Originating-Client: open-xchange-appsuite X-CMAE-Envelope: MS4wfB2gGEreEOWcTqe8zkuhGV2yn4doSidnx9Fk7UT5dntShoatAmZusXTzJsTnUk/Iziv8ABYyWlzMlM4vff2IIqLKRH9M+lP630l4BLzCiFR7uj5ZrtX1 v23ijHe/ZbnuMIpHIthgFRLD+NMretQMplHrXEh/ZqEOy1BSntuukxcMZKRG3ZdSXpDJfed+dVeG6TPLfOMCRAbQgzj9m0U9YWF4LjPFzDdYcWbwf5pbv7Ak ixnG05hHG/7tXaaKNH8WnJ4yTWBedTyQh1ZATkcOMC7bIDepisYvTCWE3AJa4QCv > On 19 June 2020 at 07:38 Lawrence Vel=C3=A1zquez wrote: > Anyway, unless I'm missing something, POSIX seems pretty clear about > this, as far as $((...)) goes: >=20 > The expression shall be treated as if it were in double-quotes, > except that a double-quote inside the expression is not treated > specially. The shell shall expand all tokens in the expression > for parameter expansion, command substitution, and **quote > removal**. [Emphasis mine.] >=20 > Next, the shell shall treat this as an arithmetic expression > and substitute the value of the expression. >=20 > https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html= #tag_18_06_04 It's straightforward just to treat double quotes as if they're a random spacing character. Not sure the error is actually useful? There was a test for it but that was simply to make sure we did something with them. pws 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) =09case ' ': /* Fall through! */ =09case '\t': =09case '\n': +=09case '"': /* POSIX says ignore these */ +=09case Dnull: =09 break; =09default: =09 if (idigit(*--ptr) || *ptr =3D=3D '.') 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 =20 + fail=3D39 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 =20 alias 3=3Decho print $(( 3 + "OK"); echo "Worked") @@ -487,3 +488,8 @@ let noexist=3D=3D0 ) 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