From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26272 invoked by alias); 9 Aug 2016 01:21:22 -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: 39009 Received: (qmail 26567 invoked from network); 9 Aug 2016 01:21:22 -0000 X-Qmail-Scanner-Diagnostics: from mail-pf0-f194.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.192.194):SA:0(0.0/5.0):. Processed in 0.194801 secs); 09 Aug 2016 01:21:22 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at brasslantern.com does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=hna/7xZma4Xq9amha09J42+50Yu40j77tOxTxA/QrVM=; b=T8jchSChpoLoohkmNQ9zYqbfaGLQEr2X8WTbrlO9a9ulaBPsTeH1GH8G5aZeV3PZ+w rk99PMRUwbTN6n57OjAkfIxvJAOodGiFoVRqhbqFKaUr/Vu6QuhMAqPGUJERYJhR58fe wsNms81RuAcFy0KPA6gmePLWYo+2G0kcykoCUfXLpGjjNqfOR/y/Lg8smbGz4K69T2v8 79JFxt6s6Os+dECQwPAnymuuJuqx0Ie0+Z8ynVOI6r+GslYZGLoDIDczTamMRfx0YUSR y8ZvuQYitXMilxi0uoOmHqKF1UtJmYqn2ksOv46cJH83YGYfuQKMi0p4ZEFDm0Di3Jdk kISQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=hna/7xZma4Xq9amha09J42+50Yu40j77tOxTxA/QrVM=; b=ABOlEdYd4E3qAYMwR84IQQDWMzEFUmsvLF1Q/WWwIJBu/2nBIo3a9UIPNqVXcIjwEr LrRliArIjGqzgytAskx2ItLNKpv2efnaxt1Ivvm5SwBysAbvLItziphMEITL/ZYaJUr+ yaU1SBsIA/cIVe5OvPRLMB2AtzYBu/fXRbDL5AbsQI7fi8EHknTt503zyhDYnFmurD5Z /LJ6oCJKLE3yJPgofmKK3UKklRTBE6/FeFgSOLOYF+QjKuX/KnFzYoQrkppAASxwMn3c PG/sX6zYedTKy1Bsyp/wGrklv/miP57TInI7EhkpQss5ABATLZvxPt+Us4LPp+dUXxai kseA== X-Gm-Message-State: AEkoousqVTvl6qyJk2zVmbDfkQA7y7lcWrl3WjxVuhI5b3oOxKMWCNnMElNy6S8Jvxq1kQ== X-Received: by 10.98.30.133 with SMTP id e127mr168003289pfe.104.1470705676065; Mon, 08 Aug 2016 18:21:16 -0700 (PDT) From: Bart Schaefer Message-Id: <160808182124.ZM9355@torch.brasslantern.com> Date: Mon, 8 Aug 2016 18:21:24 -0700 In-Reply-To: <20160808192734.21923640@ntlworld.com> Comments: In reply to Peter Stephenson "Re: [bug] shwordsplit not working on $@ when $# > 1" (Aug 8, 7:27pm) References: <20160808111626.GA19766@chaz.gmail.com> <20160808192734.21923640@ntlworld.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: [bug] shwordsplit not working on $@ when $# > 1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Aug 8, 7:27pm, Peter Stephenson wrote: } Subject: Re: [bug] shwordsplit not working on $@ when $# > 1 } } The variable isarr from the value entry v->isarr is negative, so we } don't go into the loop that does joining and splitting as that } explicitly asks for (isarr >= 0). (It was 0 for a scalar, hence the } first case above.) It's not really a loop; it's just the "if" block at subst.c:3457. This block first joins all the array elements on the first character of $IFS, and then splits the resulting string on spaces. The problem is that in this case we want split but in the case of users/15439 we do NOT want join. The patch called out by Jeremie prevents the joining, but does so by bypassing the splitting; it first sets nojoin nonzero by examining IFS, and then sets isarr = -1 when nojoin is true (i.e., the negative isarr you saw is not coming from v->isarr, so the value of SCANPM_ISVAR_AT is a red herring). The underlying assumption that it works to first join on $IFS and then split again to get the array leads to the error, because when $IFS is empty there won't be anything to split on, but when there is no join the new array must be built by splitting every element of the value array (and there is currently no code that does that). I *think* we can untangle this as follows, but then again I thought I had untangled in in workers/29313, too. This relies on the idea that if we already have an array when nojoin, then we're not going to split it again, which seems dubious somehow if there is explicit use of the (s:-:) flag. It may be that we really do need to write a loop over the existing elements when isarr is true there. Existing tests still pass, but then they always did, this needs a new one. Holding off until we think of other edge cases. diff --git a/Src/subst.c b/Src/subst.c index e3af156..6dd4608 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -3454,13 +3454,13 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, * exception is that ${name:-word} and ${name:+word} will have already * done any requested splitting of the word value with quoting preserved. */ - if (ssub || (spbreak && isarr >= 0) || spsep || sep) { - if (isarr) { + if (ssub || spbreak || spsep || sep) { + if (isarr && !nojoin) { val = sepjoin(aval, sep, 1); isarr = 0; ms_flags = 0; } - if (!ssub && (spbreak || spsep)) { + if (!ssub && (spbreak || spsep) && !isarr) { aval = sepsplit(val, spsep, 0, 1); if (!aval || !aval[0]) val = dupstring(""); @@ -3527,7 +3527,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, } /* * TODO: It would be really quite nice to abstract the - * isarr and !issarr code into a function which gets + * isarr and !isarr code into a function which gets * passed a pointer to a function with the effect of * the promptexpand bit. Then we could use this for * a lot of stuff and bury val/aval/isarr inside a structure