zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: zsh-workers@sunsite.auc.dk
Subject: Singleton arrays treated as scalars (redux)
Date: Tue, 1 Jun 1999 04:50:15 +0000	[thread overview]
Message-ID: <990601045015.ZM9744@candle.brasslantern.com> (raw)

I think I've figured out why paramsubst() converts one-element arrays into
scalars.  Consider the case where zsh needs to expand

	some${param}thing

When param is a scalar, it simply concatenates "some" and "thing" with the
value, and then performs globsubst if necessary.

When param is an array of two or more elements, it concatenates "some" with
the first element and globsubsts, does globsubst on any internal elements,
and finally concatenates the last element with "thing" and does one last
globsubst on that.

The one-element array case can't be handled like the two-or-more case; it
must be handled like the scalar case.  So zsh does the simplest thing, and
turns the array into a scalar so that it will take that code branch.  This
also prevents it from attempting plan9 (rcexpandparam) concatenation when
there is only one element.

I think mult_isarr is being assigned from isarr early enough that this is
no longer an issue in 3.1.5, and as far as I can tell it's never been an
issue in 3.0.5 (that is, new 3.1.5-pws-* code is what brought all this up;
if someone has a counter-example please tell me).

However, there's one spot where I think mult_isarr is not correctly set,
and another spot where isarr is compared to 2 even though in that branch
it can't possibly have any value other than 0.  Patch appended, someone
please check it for sanity.

Index: Src/subst.c
@@ -1484,6 +1484,10 @@
 	val = dupstring("");
 	isarr = 0;
     } else if (isarr && aval && aval[0] && !aval[1]) {
+	/* treat a one-element array as a scalar for purposes of   *
+	 * concatenation with surrounding text (some${param}thing) *
+	 * and rc_expand_param handling.  Note: mult_isarr (above) *
+	 * propagates the true array type from nested expansions.  */
 	val = aval[0];
 	isarr = 0;
     }
@@ -1500,8 +1504,8 @@
 		val = aval[0];
 	    else
 		isarr = 2;
-	    mult_isarr = isarr;
 	}
+	mult_isarr = isarr;
     }
     if (casmod) {
 	if (isarr) {
@@ -1665,7 +1669,7 @@
 	    return NULL;
 	xlen = strlen(x);
 	*str = strcatsub(&y, ostr, aptr, x, xlen, fstr, globsubst);
-	if (qt && !*y && isarr != 2)
+	if (qt && !*y)
 	    y = dupstring(nulstring);
 	setdata(n, (void *) y);
     }

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


             reply	other threads:[~1999-06-01  4:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-01  4:50 Bart Schaefer [this message]
1999-06-01  8:49 Sven Wischnowsky

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=990601045015.ZM9744@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).