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

Fix command substitutions run on the same line as a here-doc (#91)

When a command substitution is run on the same line as a here-document,
a syntax error occurs due to a regression introduced in ksh93u+ 2011-04-15:

true << EOF; true $(true)
EOF
syntax error at line 1: `<<EOF' here-document not contained within command substitution

The regression is caused by an error check that was added to make
the following script causes a syntax error (because the here-document
isn't completed inside of the command substitution):

$(true << EOF)
EOF

src/cmd/ksh93/sh/lex.c:
- Only throw an error when a here-document in a command substitution
  isn't completed inside of the command substitution.

src/cmd/ksh93/tests/heredoc.sh:
- Add a regression test for running a command substitution on the
  same line as a here-document.
- Add a missed regression test for using here-documents in command
  substitutions. This is the original bug that was fixed in ksh93u+
  2011-04-15 (it is why the error message was added), but a regression
  test for here-documents in command substitutions wasn't added in
  that version.

This bugfix was backported from ksh93v- 2013-10-10-alpha.
This commit is contained in:
Johnothan King 2020-07-23 16:03:57 -07:00 committed by GitHub
parent f207cd5787
commit 6e515f1d45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 2 deletions

View file

@ -498,4 +498,16 @@ print foo > $tmp/foofile
x=$( $SHELL 2> /dev/null 'read <<< $(<'"$tmp"'/foofile) 2> /dev/null;print -r "$REPLY"')
[[ $x == foo ]] || err_exit '<<< $(<file) not working'
# ======
# A syntax error should not occur if a command substitution is run on the same line
# as a here document.
$SHELL -c 'true << EOF || true "$(true)"
EOF' || err_exit 'placing a command substitution and here-doc on the same line causes a syntax error'
# A here-document in a command substitution should cause a syntax error if it isn't
# completed inside of the command substitution.
$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"
# ======
exit $((Errors<125?Errors:125))