mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix line continuation within command substitutions
In command substitutions of the $(standard) and ${ shared state; }
form, backslash line continuation is broken.
Reproducer:
echo $(
echo one two\
three
)
Actual output (ksh93, all versions):
one two\ three
Expected output (every other shell, POSIX spec):
one twothree
src/cmd/ksh93/sh/lex.c: sh_lex(): case S_REG:
- Do not skip new-line joining if we're currently processing a
command substitution of one of these forms (i.e., if the
lp->lexd.dolparen level is > 0).
Background info/analysis:
comsub() is called from sh_lex() when S_PAR is the current state.
In src/cmd/ksh93/data/lexstates.c, we see that S_PAR is reached in
the ST_DOL state table at index 40. Decimal 40 is ( in ASCII. So,
the previous skipping of characters was done according to the
ST_DOL state table, and the character that stopped it was (. This
means we have $(.
Alternatively, comsub() may be called from sh_lex() by jumping to
the do_comsub label. In brief, that is the case when we have ${.
Regardless of which it is from the two, comsub() is now called from
sh_lex(). In comsub(), lp->lexd.dolparen is incremented at the
beginning and decremented at the end. Between them, we see that
sh_lex() is called. So, lp->lexd.dolparen in sh_lex() indicates the
depth of nesting $( or ${ statements we're in. Thus, it is also the
number of comsub() invocations seen in a backtrace taken in
sh_lex().
The codepath for `...` is different (and never had this bug).
Co-authored by: Martijn Dekker <martijn@inlv.org>
Resolves: https://github.com/ksh93/ksh/issues/367
This commit is contained in:
parent
40a5c45b48
commit
9bed28c3f9
4 changed files with 33 additions and 4 deletions
|
|
@ -295,5 +295,28 @@ got="${var:+'}text between expansions${var:+'}"
|
|||
got=$(eval 'foo="`: "^Exec(\[[^]=]*])?="`"' 2>&1) || err_exit "Backtick command substitutions can't nest double quotes" \
|
||||
"(got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
# https://github.com/ksh93/ksh/issues/367
|
||||
exp='one twothree'
|
||||
got=$(
|
||||
echo one two\
|
||||
three
|
||||
)
|
||||
[[ $got == "$exp" ]] || err_exit "Line continuation broken within standard command substitution" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
got=${
|
||||
echo one two\
|
||||
three
|
||||
}
|
||||
[[ $got == "$exp" ]] || err_exit "Line continuation broken within shared-state command substitution" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
# backticks did not have this bug but let's test them anyway
|
||||
got=`
|
||||
echo one two\
|
||||
three
|
||||
`
|
||||
[[ $got == "$exp" ]] || err_exit "Line continuation broken within backtick command substitution" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue