zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: [bug] shwordsplit not working on $@ when $# > 1
Date: Wed, 10 Aug 2016 17:39:35 -0700	[thread overview]
Message-ID: <160810173935.ZM26818@torch.brasslantern.com> (raw)
In-Reply-To: <20160810135613.6c4fa427@pwslap01u.europe.root.pri>

On Aug 10,  1:56pm, Peter Stephenson wrote:
} Subject: Re: [bug] shwordsplit not working on $@ when $# > 1
}
} > Existing tests still pass, but then they always did, this needs a
} > new one.  Holding off until we think of other edge cases.
} 
} This tests the significant cases with $@.

OK, this replaces both workers/39009 and workers/39013 -- to the latter
it adds three more tests based on workers/39018.  I also re-ordered the
statements in the 39013 tests to make it obvious that IFS doesn't have
an effect on the "set -- ..." statements.


diff --git a/Src/subst.c b/Src/subst.c
index e3af156..ae3e4c4 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -3454,13 +3454,22 @@ 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 (ssub || spbreak || spsep || sep) {
+	int force_split = !ssub && (spbreak || spsep);
 	if (isarr) {
-	    val = sepjoin(aval, sep, 1);
-	    isarr = 0;
-	    ms_flags = 0;
+	    if (nojoin == 0) {
+		val = sepjoin(aval, sep, 1);
+		isarr = 0;
+		ms_flags = 0;
+	    } else if (force_split && nojoin == 2) {
+		/* Hack to simulate splitting individual elements:
+		 * first join on what we later use to split
+		 */
+		val = sepjoin(aval, spsep, 1);
+		isarr = 0;
+	    }
 	}
-	if (!ssub && (spbreak || spsep)) {
+	if (force_split && !isarr) {
 	    aval = sepsplit(val, spsep, 0, 1);
 	    if (!aval || !aval[0])
 		val = dupstring("");
@@ -3527,7 +3536,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
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 7cb297e..35630c5 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -1920,3 +1920,58 @@
   print $array
 0:"-" works after "[" in same expression (Dash problem)
 >foo two three
+
+  (
+  setopt shwordsplit
+  set -- whim:wham:whom
+  IFS=:
+  print -l $@
+  )
+0:Splitting of $@ on IFS: single element
+>whim
+>wham
+>whom
+
+  (
+  setopt shwordsplit
+  set -- one:two bucklemy:shoe
+  IFS=:
+  print -l $@
+  )
+0:Splitting of $@ on IFS: multiple elements
+# No forced joining in this case
+>one
+>two
+>bucklemy
+>shoe
+
+  (
+  set -- one:two bucklemy:shoe
+  print -l ${(s.:.)@}
+  )
+0:Splitting of $@ on (s): multiple elements
+# Forced joining in this case
+>one
+>two bucklemy
+>shoe
+
+  (
+  set -- one:two bucklemy:shoe
+  print -l ${(@s.:.)@}
+  )
+0:Splitting of $@ on (@s): multiple elements
+# Forced non-joining in this case
+>one
+>two
+>bucklemy
+>shoe
+
+  (
+  set -- one:two bucklemy:shoe
+  IFS=
+  setopt shwordsplit
+  print -l ${@}
+  )
+0:Joining of $@ does not happen when IFS is empty
+>one:two
+>bucklemy:shoe


      reply	other threads:[~2016-08-11  0:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-08 11:16 Stephane Chazelas
2016-08-08 17:28 ` Bart Schaefer
2016-08-08 18:02   ` Jérémie Roquet
2016-08-08 18:27 ` Peter Stephenson
2016-08-09  1:21   ` Bart Schaefer
2016-08-09  8:40     ` Peter Stephenson
2016-08-10 17:28       ` Bart Schaefer
2016-08-11 10:05         ` Peter Stephenson
2016-08-11 17:28           ` Bart Schaefer
2016-08-12  7:50             ` Bart Schaefer
2016-08-10 12:56     ` Peter Stephenson
2016-08-11  0:39       ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=160810173935.ZM26818@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).