Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 23, 2020

Conversation

JohnoKing
Copy link

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:

$ cat ./foo.sh
true << EOF; true $(true)
EOF
$ ksh ./foo.sh
./foo.sh: syntax error at line 1: `<<EOF' here-document not contained within command substitution

The regression is caused by the following error check, which was added to fix a bug with here-documents in command substitutions:

ksh/src/cmd/ksh93/sh/lex.c

Lines 1692 to 1693 in f207cd5

if(lp->heredoc)
errormsg(SH_DICT,ERROR_exit(SYNBAD),e_lexsyntax5,lp->sh->inlineno,lp->heredoc->ioname);

# A syntax error should occur because the here-document isn't completed
# in the command substitution, but in versions of ksh prior to ksh93u+
# 2011-04-15 this isn't an error.
$(true << EOF)
EOF

The bugfix (which was backported from ksh93v- 2013-10-10-alpha) stops the syntax error from occurring when a here-document is not inside of a command substitution. It should only be a syntax error when a here-document inside of a command substitution isn't completed before the ending ')'.

@JohnoKing JohnoKing force-pushed the fix-comsub-heredoc branch from b7faa11 to e5373e8 Compare July 23, 2020 22:32
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.
@JohnoKing JohnoKing force-pushed the fix-comsub-heredoc branch from e5373e8 to ce32b51 Compare July 23, 2020 22:33
@McDutchie McDutchie merged commit 6e515f1 into ksh93:master Jul 23, 2020
@JohnoKing JohnoKing deleted the fix-comsub-heredoc branch July 24, 2020 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants