Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [bug] shwordsplit not working on $@ when $# > 1
- X-seq: zsh-workers 39009
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: [bug] shwordsplit not working on $@ when $# > 1
- Date: Mon, 8 Aug 2016 18:21:24 -0700
- 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==
- In-reply-to: <20160808192734.21923640@ntlworld.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20160808111626.GA19766@chaz.gmail.com> <20160808192734.21923640@ntlworld.com>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author