git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
HXHerbert Xu <herbert@gondor.apana.org.au>
Date
May 5, 2007, 08:03 UTC
Message-ID
<20070505080313.GA12170@gondor.apana.org.au>
In-Reply-To
<20061219003557.GA17799@gondor.apana.org.au>
On Tue, Dec 19, 2006 at 11:35:57AM +1100, herbert wrote:
Show 13 quoted lines
> 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.

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~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Previous: Herbert XuNext: Jeff King
Message 5 of 7 in “git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard”
  1. git-parse-remote: fix ambiguous shell bug in expand_refs_wildcardJeff King, Dec 18, 2006
  2. Jeff KingDec 18, 2006
  3. Jeff KingDec 18, 2006
  4. Herbert XuDec 19, 2006
  5. Herbert XuMay 5, 2007
  6. Jeff KingMay 7, 2007
  7. Herbert XuMay 7, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.