1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Allow double quotes within backtick comsub within double quotes

The following reproducer causes a spurious syntax error:

    foo="`: "("`"

The nested double quotes are not recognised correctly, causing a
syntax error at the '('. Removing the outer double quotes (which
are unnecessary) is a workaround, but it's still a bug as every
other shell accepts this. This bug has been present since the
original Bourne shell.

src/cmd/ksh93/sh/lex.c: sh_lex(): case S_QUOTE:
- If the current character is '"' and we're in a `...` command
  substitution (ingrave is true), then do not switch to the old
  mode but keep using the ST_QUOTE state table.

Thanks to @JohnoKing for the report and to @atheik for the fix.

Co-authored by: Martijn Dekker <martijn@inlv.org>
Resolves: https://github.com/ksh93/ksh/issues/352
This commit is contained in:
atheik 2022-05-20 22:29:20 +01:00 committed by Martijn Dekker
parent c86713455c
commit 40a5c45b48
4 changed files with 25 additions and 3 deletions

View file

@ -772,8 +772,19 @@ int sh_lex(Lex_t* lp)
{
if(sh.inlineno > lp->lastline)
lp->lex.last_quote = c;
mode = oldmode(lp);
poplevel(lp);
/*
* At this point, we know that the previous skipping of characters was done
* according to the ST_QUOTE state table. We also know that the character that
* stopped the skipping is also the ending character for the current level. If
* that character was " and if we are in a `...` statement, then don't switch
* to the old mode, as we are actually at the innermost section of a "`"..."`"
* statement, which should be skipped again using the ST_QUOTE state table.
*/
if(c!='"' || !ingrave)
{
mode = oldmode(lp);
poplevel(lp);
}
}
else if(c=='"' && n==RBRACE)
mode = ST_QNEST;