zsh-workers
 help / color / mirror / code / Atom feed
* regression in ${##""}
@ 2011-06-03 18:00 Eric Blake
  2011-06-03 18:55 ` Mikael Magnusson
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Blake @ 2011-06-03 18:00 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 520 bytes --]

POSIX requires ${##""} to be parsed as ${parameter#word} with parameter
of # and word of "", which results in the output of $# with the shortest
prefix of the empty string removed (aka ${#}).  But current zsh.git
rejects this:

$ ./Src/zsh -c 'set a b; echo ${##""}'
zsh:1: bad substitution

Worse, this is a regression:

$ zsh -c 'set a b; echo ${##""}'
2
$ rpm -q zsh
zsh-4.3.10-5.fc14.x86_64

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: regression in ${##""}
  2011-06-03 18:00 regression in ${##""} Eric Blake
@ 2011-06-03 18:55 ` Mikael Magnusson
  2011-06-03 19:16   ` Eric Blake
  2011-06-03 20:16   ` Peter Stephenson
  0 siblings, 2 replies; 4+ messages in thread
From: Mikael Magnusson @ 2011-06-03 18:55 UTC (permalink / raw)
  To: Eric Blake; +Cc: zsh-workers

On 3 June 2011 20:00, Eric Blake <eblake@redhat.com> wrote:
> POSIX requires ${##""} to be parsed as ${parameter#word} with parameter
> of # and word of "", which results in the output of $# with the shortest
> prefix of the empty string removed (aka ${#}).  But current zsh.git
> rejects this:
>
> $ ./Src/zsh -c 'set a b; echo ${##""}'
> zsh:1: bad substitution
>
> Worse, this is a regression:
>
> $ zsh -c 'set a b; echo ${##""}'
> 2
> $ rpm -q zsh
> zsh-4.3.10-5.fc14.x86_64

Not a surprise, this is due to

28889: ${##} should return the length of $#

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: regression in ${##""}
  2011-06-03 18:55 ` Mikael Magnusson
@ 2011-06-03 19:16   ` Eric Blake
  2011-06-03 20:16   ` Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Blake @ 2011-06-03 19:16 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1067 bytes --]

On 06/03/2011 12:55 PM, Mikael Magnusson wrote:
> On 3 June 2011 20:00, Eric Blake <eblake@redhat.com> wrote:
>> POSIX requires ${##""} to be parsed as ${parameter#word} with parameter
>> of # and word of "", which results in the output of $# with the shortest
>> prefix of the empty string removed (aka ${#}).  But current zsh.git
>> rejects this:
>>
>> $ ./Src/zsh -c 'set a b; echo ${##""}'
>> zsh:1: bad substitution
>>
>> Worse, this is a regression:
>>
>> $ zsh -c 'set a b; echo ${##""}'
>> 2
>> $ rpm -q zsh
>> zsh-4.3.10-5.fc14.x86_64
> 
> Not a surprise, this is due to
> 
> 28889: ${##} should return the length of $#

Before you go changing anything, though, I just filed a bug against POSIX:

http://austingroupbugs.net/view.php?id=457

which recommends that ${parameter#word} and ${parameter##word} be
changed to be unspecified if parameter is #; this relaxation in the
standard would permit current zsh behavior.

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: regression in ${##""}
  2011-06-03 18:55 ` Mikael Magnusson
  2011-06-03 19:16   ` Eric Blake
@ 2011-06-03 20:16   ` Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2011-06-03 20:16 UTC (permalink / raw)
  To: zsh-workers

On Fri, 3 Jun 2011 20:55:00 +0200
Mikael Magnusson <mikachu@gmail.com> wrote:
> > $ ./Src/zsh -c 'set a b; echo ${##""}'
> > zsh:1: bad substitution
> 
> Not a surprise, this is due to
> 
> 28889: ${##} should return the length of $#

Indeed.  How not to define a language, lesson 1:  make the same
symbol have three different meanings in a single expression.

I confess that zsh's own parameter syntax is actually starting to look
rather more attractive... just not very.

Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.124
diff -p -u -r1.124 subst.c
--- Src/subst.c	23 May 2011 16:08:47 -0000	1.124
+++ Src/subst.c	3 Jun 2011 20:13:21 -0000
@@ -2080,7 +2080,16 @@ paramsubst(LinkList l, LinkNode n, char 
 		    || (cc = s[1]) == '*' || cc == Star || cc == '@'
 		    || cc == '?' || cc == Quest
 		    || cc == '$' || cc == String || cc == Qstring
-		    || cc == '#' || cc == Pound
+		    /*
+		     * Me And My Squiggle:
+		     * ${##} is the length of $#, but ${##foo}
+		     * is $# with a "foo" removed from the start.
+		     * If someone had defined the *@!@! language
+		     * properly in the first place we wouldn't
+		     * have this nonsense.
+		     */
+		    || ((cc == '#' || cc == Pound) &&
+			s[2] == Outbrace)
 		    || cc == '-' || (cc == ':' && s[2] == '-')
 		    || (isstring(cc) && (s[2] == Inbrace || s[2] == Inpar)))) {
 	    getlen = 1 + whichlen, s++;
Index: Test/D04parameter.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v
retrieving revision 1.57
diff -p -u -r1.57 D04parameter.ztst
--- Test/D04parameter.ztst	19 May 2011 16:24:38 -0000	1.57
+++ Test/D04parameter.ztst	3 Jun 2011 20:13:21 -0000
@@ -179,9 +179,17 @@
   print ${##}
   set 1 2 3 4 5 6 7 8 9 10
   print ${##}
-0:${##} is length of $#
+  print ${##""}
+  print ${##1}
+  print ${##2}
+  print ${###<->} # oh, for pete's sake...
+0:${##} is length of $#, and other tales of hash horror
 >1
 >2
+>10
+>0
+>10
+>
 
   array=(once bitten twice shy)
   print IF${array}THEN


-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-06-03 20:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-03 18:00 regression in ${##""} Eric Blake
2011-06-03 18:55 ` Mikael Magnusson
2011-06-03 19:16   ` Eric Blake
2011-06-03 20:16   ` Peter Stephenson

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).