{"thread":{"id":"7981","subject":"Re: [PATCH] git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard","startedAt":"2006-12-18T08:09:41Z","lastAt":"2007-05-07T08:01:17Z","messageCount":7,"participants":["Herbert Xu","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"294108","messageId":"20061218080941.GA3857@coredump.intra.peff.net","threadId":"7981","inReplyTo":null,"subject":"[PATCH] git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2006-12-18T08:09:41Z","receivedAt":"2006-12-18T08:09:41Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"Bash and dash parse \"${name%'^{}'}\" differently, with bash quoting the\n^{}, and dash assuming the first } is the end of the variable (and thus\ntacking '} to the end). Instead, use backslash to quote the closing\nbrace.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nPlease sanity check that I understand what the code is supposed to be\ndoing. The bug I was getting was this:\n\n$ readlink /bin/sh\ndash\n$ git-clone git://git.kernel.org/pub/scm/git/git.git\n[...]\n$ cd git && git-pull\nWarning: No merge candidate found because value of config option\n         \"branch.master.merge\" does not match any remote branch fetched.\n\nA shell trace showed lots of tests against strings like\n\"refs/heads/master'}\". Expand_refs_wildcard returned no entries, so it\ncouldn't match the branch.master.merge field.\n\n git-parse-remote.sh |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/git-parse-remote.sh b/git-parse-remote.sh\nindex f27c3c2..ab79042 100755\n--- a/git-parse-remote.sh\n+++ b/git-parse-remote.sh\n@@ -116,7 +116,7 @@ expand_refs_wildcard () {\n \t\t\twhile read sha1 name\n \t\t\tdo\n \t\t\t\tmapped=${name#\"$from\"}\n-\t\t\t\tif test \"z$name\" != \"z${name%'^{}'}\" ||\n+\t\t\t\tif test \"z$name\" != \"z${name%'^{\\}'}\" ||\n \t\t\t\t\ttest \"z$name\" = \"z$mapped\"\n \t\t\t\tthen\n \t\t\t\t\tcontinue\n-- \n"},{"id":"296359","messageId":"20061218081627.GB3857@coredump.intra.peff.net","threadId":"7981","inReplyTo":"20061218080941.GA3857@coredump.intra.peff.net","subject":"Re: [PATCH] git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2006-12-18T08:16:27Z","receivedAt":"2006-12-18T08:16:27Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Dec 18, 2006 at 03:09:41AM -0500, Jeff King wrote:\n\n> -\t\t\t\tif test \"z$name\" != \"z${name%'^{}'}\" ||\n> +\t\t\t\tif test \"z$name\" != \"z${name%'^{\\}'}\" ||\n\nUrgh, sorry, this is wrong. It should be:\n  ${name%^{\\}}\nIOW, the \\ replaces the quote, not in addition to.\n\n"},{"id":"296373","messageId":"20061218224505.GB13034@coredump.intra.peff.net","threadId":"7981","inReplyTo":"7v4prtx9hu.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2006-12-18T22:45:05Z","receivedAt":"2006-12-18T22:45:05Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Dec 18, 2006 at 11:57:33AM -0800, Junio C Hamano wrote:\n\n> Sounds like a dash bug, if my reading of 2.6.2 Parameter\n> Expansion is correct:\n> \n>     http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html\n\nInterestingly, this works in dash:\n\n$ foo=bar}\n$ echo ${foo%'}'}\nbar\n\nbut doing it inside an interpolated string doesn't:\n\n$ foo=bar}\n$ echo \"${foo%'}'}\"\nbar}'}\n\n> This would be another way to work it around.  Both dash and bash\n> say 'foo':\n> \n>         $ suf='^{}'\n>         $ name='foo^{}'\n>         $ echo \"${name%$suf}\"\n>         foo\n> \n> I think this might be easier to read than using \"^{\\}\".\n\nThat seems reasonable to me.\n\n"},{"id":"294512","messageId":"20061219003557.GA17799@gondor.apana.org.au","threadId":"7981","inReplyTo":"20061218224505.GB13034@coredump.intra.peff.net","subject":"Re: [PATCH] git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard","fromName":"Herbert Xu","fromEmail":"herbert@gondor.apana.org.au","sentAt":"2006-12-19T00:35:57Z","receivedAt":"2006-12-19T00:35:57Z","isPatch":true,"sender":{"key":"herbert@gondor.apana.org.au","avatar":null},"body":"On Mon, Dec 18, 2006 at 05:45:05PM -0500, Jeff King wrote:\n> \n> but doing it inside an interpolated string doesn't:\n> \n> $ foo=bar}\n> $ echo \"${foo%'}'}\"\n> bar}'}\n\nYes it's a bug in dash.  Both quote marks (\" and ') are represented\nby the same char internally before processing which is where the\nmix-up occurs.\n\nI'll work on a fix.\n\nCheers,\n-- \nVisit Openswan at http://www.openswan.org/\nEmail: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>\nHome Page: http://gondor.apana.org.au/~herbert/\n"},{"id":"41125","messageId":"20070505080313.GA12170@gondor.apana.org.au","threadId":"7981","inReplyTo":"20061219003557.GA17799@gondor.apana.org.au","subject":"Re: [PATCH] git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard","fromName":"Herbert Xu","fromEmail":"herbert@gondor.apana.org.au","sentAt":"2007-05-05T08:03:13Z","receivedAt":"2007-05-05T08:03:13Z","isPatch":true,"sender":{"key":"herbert@gondor.apana.org.au","avatar":null},"body":"On Tue, Dec 19, 2006 at 11:35:57AM +1100, herbert wrote:\n> On Mon, Dec 18, 2006 at 05:45:05PM -0500, Jeff King wrote:\n> > \n> > but doing it inside an interpolated string doesn't:\n> > \n> > $ foo=bar}\n> > $ echo \"${foo%'}'}\"\n> > bar}'}\n> \n> Yes it's a bug in dash.  Both quote marks (\" and ') are represented\n> by the same char internally before processing which is where the\n> mix-up occurs.\n> \n> I'll work on a fix.\n\nSorry for the delay.  I've finally looked at fixing this.  It turns out\nthat dash's behaviour is actually correct and POSIX compliant.\n\nIt's correct because dash treats all single quotes within double\nquotes (except those within command substitutions) as literals.\nThis interpretation is also supported by POSIX.\n\nIn fact the rationale (C.2.2.3) in the POSIX document explicitly\ndisallows the aformentioned usage as it violates the rule that an\neven number of single quotes if any can occur in an ${...} expression\nenclosed by double quotes.\n\nSo the correct and portable expression in this case would be either\n\necho \"${foo%\\}}\"\n\nor\n\nbrace=}\necho \"${foo%$brace}\"\n\nCheers,\n-- \nVisit Openswan at http://www.openswan.org/\nEmail: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>\nHome Page: http://gondor.apana.org.au/~herbert/\nPGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt\n"},{"id":"41293","messageId":"20070507063621.GB31445@coredump.intra.peff.net","threadId":"7981","inReplyTo":"20070505080313.GA12170@gondor.apana.org.au","subject":"Re: [PATCH] git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-05-07T06:36:22Z","receivedAt":"2007-05-07T06:36:22Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, May 05, 2007 at 06:03:13PM +1000, Herbert Xu wrote:\n\n> In fact the rationale (C.2.2.3) in the POSIX document explicitly\n> disallows the aformentioned usage as it violates the rule that an\n> even number of single quotes if any can occur in an ${...} expression\n> enclosed by double quotes.\n\nYes, there's not much room for interpretation; the old git code was\nclearly bogus (we are working around it by using sed instead). Thanks\nfor tracking this down, Herbert.\n\nIt looks like bash is actually broken in POSIXLY_CORRECT mode, then:\n\n$ echo $BASH_VERSION\n3.1.17(1)-release\n$ POSIXLY_CORRECT=1\n$ foo=bar}\n$ echo \"${foo%'}'}\"\nbar\n\nMy interpretation of the correct behavior is that it should remove a\nsingle quote from the end of foo, and then print '} literally (that is,\nsingle quote and brace).\n\n-Peff\n"},{"id":"41302","messageId":"20070507080117.GA5302@gondor.apana.org.au","threadId":"7981","inReplyTo":"20070507063621.GB31445@coredump.intra.peff.net","subject":"Re: [PATCH] git-parse-remote: fix ambiguous shell bug in expand_refs_wildcard","fromName":"Herbert Xu","fromEmail":"herbert@gondor.apana.org.au","sentAt":"2007-05-07T08:01:17Z","receivedAt":"2007-05-07T08:01:17Z","isPatch":true,"sender":{"key":"herbert@gondor.apana.org.au","avatar":null},"body":"On Mon, May 07, 2007 at 02:36:22AM -0400, Jeff King wrote:\n>\n> It looks like bash is actually broken in POSIXLY_CORRECT mode, then:\n> \n> $ echo $BASH_VERSION\n> 3.1.17(1)-release\n> $ POSIXLY_CORRECT=1\n> $ foo=bar}\n> $ echo \"${foo%'}'}\"\n> bar\n> \n> My interpretation of the correct behavior is that it should remove a\n> single quote from the end of foo, and then print '} literally (that is,\n> single quote and brace).\n\nWell strictly speaking this is allowed by the standard as this usage\ncontains an odd number of single quotes inside an ${...} expression\nenclosed by double quotes, which behaves in an implementation-specific\nmanner.\n\nCheers,\n-- \nVisit Openswan at http://www.openswan.org/\nEmail: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>\nHome Page: http://gondor.apana.org.au/~herbert/\nPGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt\n"}]}