On 13/02/2018 14:53, Denys Vlasenko wrote:
$ >'\zzzz'
$ >'\wwww'
$ dash -c 'echo "\*"'
\wwww \zzzz

Nice catch.

The cause: uses "\\*" pattern instead of "\\\*".
The fix:

                         /* backslash */
                         case CBACK:
                                 c = pgetc2();
                                 if (c == PEOF) {
                                         USTPUTC(CTLESC, out);
                                         USTPUTC('\\', out);
                                 } else if (c == '\n') {
                                 } else {
                                         if (
                                                 dblquote &&
                                                 c != '\\' && c != '`' &&
                                                 c != '$' && (
                                                         c != '"' ||
                                                         eofmark != NULL
                                         ) {
USTPUTC(CTLESC, out); // add this line
                                                 USTPUTC('\\', out);
                                         USTPUTC(CTLESC, out);
                                         USTPUTC(c, out);

I don't think this is right. The bug was introduced in


Prior to that, the line USTPUTC(CTLESC, out); was there. The commit message is saying that the logic for detecting whether \ should be taken literally doesn't belong in the parser, that the parser will get it wrong. The example in the commit message doesn't break with your patch, but short modifications to that example do make it fail:


$ dash -c 'foo=a; echo "<${foo#[a\]]}>"'

This is what I expect, and also what bash, ksh and posh do.

With your patch:

$ dash -c 'foo=a; echo "<${foo#[a\]]}>"'

Harald van Dijk
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to