Re: [PATCH] git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard

5 messages, 2 authors, 2016-08-11 · open the first message on its own page

Re: [PATCH] git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard

From: Jeff King <hidden>
Date: 2016-08-11 20:04:29

On Mon, Dec 18, 2006 at 11:57:33AM -0800, Junio C Hamano wrote:
Sounds like a dash bug, if my reading of 2.6.2 Parameter
Expansion is correct:

    http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html
Interestingly, this works in dash:

$ foo=bar}
$ echo ${foo%'}'}
bar

but doing it inside an interpolated string doesn't:

$ foo=bar}
$ echo "${foo%'}'}"
bar}'}
This would be another way to work it around.  Both dash and bash
say 'foo':

        $ suf='^{}'
        $ name='foo^{}'
        $ echo "${name%$suf}"
        foo

I think this might be easier to read than using "^{\}".
That seems reasonable to me.

Re: [PATCH] git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: 2016-06-15 22:43:08

On Tue, Dec 19, 2006 at 11:35:57AM +1100, herbert wrote:
On Mon, Dec 18, 2006 at 05:45:05PM -0500, Jeff King wrote:
quoted
but doing it inside an interpolated string doesn't:

$ foo=bar}
$ echo "${foo%'}'}"
bar}'}
Yes it's a bug in dash.  Both quote marks (" and ') are represented
by the same char internally before processing which is where the
mix-up occurs.

I'll work on a fix.
Sorry for the delay.  I've finally looked at fixing this.  It turns out
that dash's behaviour is actually correct and POSIX compliant.

It's correct because dash treats all single quotes within double
quotes (except those within command substitutions) as literals.
This interpretation is also supported by POSIX.

In fact the rationale (C.2.2.3) in the POSIX document explicitly
disallows the aformentioned usage as it violates the rule that an
even number of single quotes if any can occur in an ${...} expression
enclosed by double quotes.

So the correct and portable expression in this case would be either

echo "${foo%\}}"

or

brace=}
echo "${foo%$brace}"

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} [off-list ref]
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

Re: [PATCH] git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard

From: Jeff King <hidden>
Date: 2016-06-15 22:43:08

On Sat, May 05, 2007 at 06:03:13PM +1000, Herbert Xu wrote:
In fact the rationale (C.2.2.3) in the POSIX document explicitly
disallows the aformentioned usage as it violates the rule that an
even number of single quotes if any can occur in an ${...} expression
enclosed by double quotes.
Yes, there's not much room for interpretation; the old git code was
clearly bogus (we are working around it by using sed instead). Thanks
for tracking this down, Herbert.

It looks like bash is actually broken in POSIXLY_CORRECT mode, then:

$ echo $BASH_VERSION
3.1.17(1)-release
$ POSIXLY_CORRECT=1
$ foo=bar}
$ echo "${foo%'}'}"
bar

My interpretation of the correct behavior is that it should remove a
single quote from the end of foo, and then print '} literally (that is,
single quote and brace).

-Peff

Re: [PATCH] git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: 2016-06-15 22:43:08

On Mon, May 07, 2007 at 02:36:22AM -0400, Jeff King wrote:
It looks like bash is actually broken in POSIXLY_CORRECT mode, then:

$ echo $BASH_VERSION
3.1.17(1)-release
$ POSIXLY_CORRECT=1
$ foo=bar}
$ echo "${foo%'}'}"
bar

My interpretation of the correct behavior is that it should remove a
single quote from the end of foo, and then print '} literally (that is,
single quote and brace).
Well strictly speaking this is allowed by the standard as this usage
contains an odd number of single quotes inside an ${...} expression
enclosed by double quotes, which behaves in an implementation-specific
manner.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} [off-list ref]
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

Re: [PATCH] git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: 2016-08-11 19:30:08

On Mon, Dec 18, 2006 at 05:45:05PM -0500, Jeff King wrote:
but doing it inside an interpolated string doesn't:

$ foo=bar}
$ echo "${foo%'}'}"
bar}'}
Yes it's a bug in dash.  Both quote marks (" and ') are represented
by the same char internally before processing which is where the
mix-up occurs.

I'll work on a fix.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} [off-list ref]
Home Page: http://gondor.apana.org.au/~herbert/
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help