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

Fix ${!} and ${$} throwing syntax error in here-document

The inclusion of the special parameter expansions ${!} and ${$}
(including the braces) in a here-document caused a syntax error.
Bug reported by @Saikiran-m on Github.

src/cmd/ksh93/data/lexstates.c: sh_lexstate7[]:
- Change the state for ! (33) and $ (36) from S_ERR to 0. State
  table 7 is for skipping over ${...}, so this avoids the S_ERR
  state being invoked in sh_lex() (lex.c) for these characters
  while skipping ${...} in a here-doc.

src/cmd/ksh93/tests/heredoc.sh:
- Test evaluating the braces expansion form for all special
  parameters (@ * # ! $ - ? 0) in a here-document.

Fixes: https://github.com/ksh93/ksh/issues/127
This commit is contained in:
Martijn Dekker 2020-09-04 04:54:35 +02:00
parent f9c127e39e
commit 6575903d1d
2 changed files with 11 additions and 1 deletions

View file

@ -274,7 +274,7 @@ static const char sh_lexstate7[256] =
S_ERR, S_ERR, S_ERR, S_ERR, S_ERR, S_ERR, S_ERR, S_ERR,
S_ERR, S_ERR, S_ERR, S_ERR, S_ERR, S_ERR, S_ERR, S_ERR,
S_ERR, S_ERR, S_ERR, S_MOD2, S_ERR, S_MOD2, S_ERR, S_ERR,
S_ERR, 0, S_ERR, S_MOD2, 0, S_MOD2, S_ERR, S_ERR,
S_ERR, S_ERR, S_MOD1, S_MOD1, S_ERR, S_MOD1, S_DOT, S_MOD2,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, S_MOD1, S_ERR, S_ERR, S_MOD1, S_ERR, S_MOD1,

View file

@ -509,5 +509,15 @@ EOF' || err_exit 'placing a command substitution and here-doc on the same line c
$SHELL -c '$(true << !)
!' 2> /dev/null && err_exit "a here-doc that isn't completed before the closing ) in a command substitution doesn't cause an error"
# ======
# Check that ${p}, where p is a special parameter, does not cause a syntax error in a here-document.
# Bug for ${!} and ${$} reported at: https://github.com/ksh93/ksh/issues/127
for p in @ \* \# ! \$ - \? 0; do
err=$(eval ': <<EOF
${'"$p"'}
EOF
' 2>&1) || err_exit "special parameter \${$p} throws syntax error in here-document (got \"$err\")"
done
# ======
exit $((Errors<125?Errors:125))