zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Bug with bash emulation regarding ':'
Date: Tue, 31 Jan 2012 20:29:09 -0800	[thread overview]
Message-ID: <120131202909.ZM6076@torch.brasslantern.com> (raw)
In-Reply-To: <20120129183644.6d49d237@pws-pc.ntlworld.com>

On Jan 29,  6:36pm, Peter Stephenson wrote:
}
} > _test ()
} > {
} > 	array="one two three"
} > 	for e in $array
} > 	do
} > 		echo "'$e'"
} > 	done
} > }
} > 
} > l=
} > : ${l:=$(_test)}
} > echo "_${l}_"
} >...
} > _'one two three'_
} 
} presumably something is going on with quoting and/or tokenisation in or
} close to multsub(), which is some of the hairier code in substitution,
} when SH_WORD_SPLIT is in effect.

Given that this sorta kinda worked back in 4.2.x ... I think the problem
is explained by this comment (dates to 4.3.0-dev-4, which means this bug
has gone unnoticed for almost exactly five years):

2619   case '-':
2620       if (vunset) {
2621           int ws = opts[SHWORDSPLIT];
2622           val = dupstring(s);
2623           /* If word-splitting is enabled, we ask multsub() to split
2624            * the substituted string at unquoted whitespace.  Then, we
2625            * turn off spbreak so that no further splitting occurs.
2626            * This allows a construct such as ${1+"$@"} to correctly
2627            * keep its array splits, and weird constructs such as
2628            * ${str+"one two" "3 2 1" foo "$str"} to only be split
2629            * at the unquoted spaces. */
2630           opts[SHWORDSPLIT] = spbreak;
2631           multsub(&val, spbreak && !aspar, (aspar ? NULL : &aval), &isarr, NULL);
2632           opts[SHWORDSPLIT] = ws;
2633           copied = 1;
2634           spbreak = 0;

The breakage in this specific example is at 2658 where SHWORDSPIT has been
forced off, but there's probably another example where the above breaks too:

2648   case Equals:
2649       if (vunset) {
2650           int ws = opts[SHWORDSPLIT];
2651           char sav = *idend;
2652           int l;
2653 
2654           *idend = '\0';
2655           val = dupstring(s);
2656           if (spsep || !arrasg) {
2657               opts[SHWORDSPLIT] = 0;
2658               multsub(&val, 0, NULL, &isarr, NULL);
2659           } else {
2660               opts[SHWORDSPLIT] = spbreak;
2661               multsub(&val, spbreak, &aval, &isarr, NULL);
2662               spbreak = 0;
2663           }
2664           opts[SHWORDSPLIT] = ws;

The problem is that we want to suppress any further splitting in the
current shell, but when we enter the subshell for $(...) it should
revert to the original setting.  I'm not sure how to pass that down
the call stack appropriately.


  reply	other threads:[~2012-02-01  4:29 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-29  2:46 Felipe Contreras
2012-01-29  5:31 ` Benjamin R. Haskell
2012-01-29 13:44   ` Felipe Contreras
2012-01-29 14:25     ` Mikael Magnusson
2012-01-29 14:27       ` Mikael Magnusson
2012-01-29 18:38       ` Vincent Lefevre
2012-01-29 18:53         ` Mikael Magnusson
2012-01-29 19:01           ` Vincent Lefevre
2012-01-29 20:30             ` Peter Stephenson
2012-01-29 21:05               ` Mikael Magnusson
2012-01-30 22:15       ` Felipe Contreras
2012-01-30 22:18         ` Mikael Magnusson
2012-01-29 18:36 ` Peter Stephenson
2012-02-01  4:29   ` Bart Schaefer [this message]
2012-02-01 16:29     ` Bart Schaefer
2012-02-05 20:11       ` Peter Stephenson
2012-02-05 21:21         ` Bart Schaefer
2012-02-10 21:04           ` Peter Stephenson
2012-02-11 21:08             ` Bart Schaefer
2012-02-12 20:29               ` Peter Stephenson
2012-02-14 17:41         ` Peter Stephenson
2012-02-14 23:30           ` Chet Ramey
2012-02-15 12:36             ` Peter Stephenson
2012-02-19 23:45               ` Bart Schaefer
2012-02-20  8:48                 ` Bart Schaefer
2012-02-20 10:59                 ` Peter Stephenson
2012-02-20 17:09                   ` Bart Schaefer
2012-01-30 19:22 ` Felipe Contreras
2012-02-10 11:08 Jilles Tjoelker

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=120131202909.ZM6076@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).