Re: dash bug: double-quoted "\" breaks glob protection for next char

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 01, 2018 at 08:24:22PM +0100, Harald van Dijk wrote:
> On 01/03/2018 00:04, Harald van Dijk wrote:
> >$ bash -c 'x=yz; echo "${x#'"'y'"'}"'
> >z
> >
> >$ dash -c 'x=yz; echo "${x#'"'y'"'}"'
> >yz
> >
> >(That is, they are executing x=yz; echo "${x#'y'}".)
> >
> >POSIX says that in "${var#pattern}" (and the same for ##, % and %%), the
> >pattern is considered unquoted regardless of the outer quotation marks.
> >Because of that, the single quote characters should not be taken
> >literally, but should be taken as quoting the y. ksh, posh and zsh agree
> >with bash.
> 
> Unfortunately, this causes another problem with all of the backslash
> approaches so far:
> 
>   x='\\\\'; printf "%s\n" "${x#'\\\\'}"
> 
> This should print a blank line. (bash, ksh, posh and zsh agree.)
> 
> Here, dash's parser stores '$\$\', where $ is a control character. preglob
> would need to turn this into \\\\\\\\. The problem is again that preglob
> cannot increase the string length. Perhaps the parser needs to store this as
> '$\$\$\$\', $ being either CTLESC or that new CTLBACK? Either way, it
> requires some more invasive changes.

These are different issues.  dash's parser currently does not
understand nested quoting in patterns at all.  That is, if your
parameter expansion are within double quotes, then dash at the
parser level will consider the pattern to be double-quoted.  Thus
any nested single-quotes will be literals instead of actual quotes.

If we fix this in the parser then everything should just work.

Cheers,
-- 
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux