From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8019 invoked by alias); 29 May 2015 15:02:48 -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: X-Seq: 35326 Received: (qmail 8214 invoked from network); 29 May 2015 15:02:45 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f4-f79c56d0000012ee-08-55687f91bac0 Date: Fri, 29 May 2015 16:02:37 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Arith parsing bug with minus after $# Message-id: <20150529160237.6f329071@pwslap01u.europe.root.pri> In-reply-to: <55676FB1.9080401@inlv.org> References: <55676FB1.9080401@inlv.org> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMLMWRmVeSWpSXmKPExsVy+t/xy7oT6zNCDW79U7c42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGduOtTEWrOapWLitg7GB8QxnFyMnh4SAiUTrwZMsELaYxIV7 69m6GLk4hASWMkpcPbuUFcKZwSQx5VQ7I0iVkMA2Rol/e6pAbBYBVYl3K9eCxdkEDCWmbpoN ZosIiEucXXsebKqwgJHErk/dzCA2r4C9xMK7f8HinAIaEpPXHGeFmKkuMe/idnYQm19AX+Lq 309MEBfZS8y8coYRoldQ4sfke2C9zAJaEpu3NbFC2PISm9e8ZYaZc+PubvYJjEKzkLTMQtIy C0nLAkbmVYyiqaXJBcVJ6bmGesWJucWleel6yfm5mxghQftlB+PiY1aHGAU4GJV4eA2upYcK sSaWFVfmHmKU4GBWEuFVD80IFeJNSaysSi3Kjy8qzUktPsQozcGiJM47d9f7ECGB9MSS1OzU 1ILUIpgsEwenVAOjpmyl+MnjE7/ylU+sqXihy3IyzS4zSXDxTO55Ng8zE57GFB7b9fviJOZQ 3+zkw1tevLuV2JgpX1XVNpPFrSrkBaesQ6iK/fV5Nme1uz5KPuX3nFJsctFy5dnfXxZuyXE+ WXXs7BZTs3vfFtlNELe/L3vkwf0p67jiTb8zcZ/t4NxibSZWmPBFiaU4I9FQi7moOBEAfNRf dlYCAAA= On Thu, 28 May 2015 21:42:41 +0200 Martijn Dekker wrote: > % set -- > % echo $# > 0 > % echo $(($#-1)) > 41 That's not a compatibility issue, that's just plain weird. I don't know the POSIX terminology. The problem is the overloading of "#" --- the test to establish what to do with it is trying too hard to resolve to ${#-}, which is a valid substitution, because it hasn't taken into account that there are no braces. So what you're seeing is ${#-}1. "-" is overloaded, too, so there could be other cases involving those two characters where they're misinterpreted, even with braces. diff --git a/Src/subst.c b/Src/subst.c index d4a04b8..168f7f1 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -2170,7 +2170,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) */ || ((cc == '#' || cc == Pound) && s[2] == Outbrace) - || cc == '-' || (cc == ':' && s[2] == '-') + || (inbrace && (cc == '-' || (cc == ':' && s[2] == '-'))) || (isstring(cc) && (s[2] == Inbrace || s[2] == Inpar)))) { getlen = 1 + whichlen, s++; /* diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index d96ffb6..c41e05e 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -1703,3 +1703,8 @@ funnychars='The qu*nk br!wan f@x j/mps o[]r \(e la~# ^"&;' [[ $funnychars = ${~${(b)funnychars}} ]] 0:${(b)...} quoting protects from GLOB_SUBST + + set -- + print $#-1 +0:Avoid confusion after overloaded characters in braceless substitution +>0-1