colis-anr / morbig

A static parser for POSIX Shell
Other
190 stars 8 forks source link

Here document in subshell → Lexical error (Unterminated nesting!). #101

Closed Niols closed 5 years ago

Niols commented 5 years ago

On:

`cat<<EOF
foo
EOF`

Morbig outputs:

Line 4, character 0: Lexical error (Unterminated nesting!).

While Dash accepts the script.

Interestingly, with $( ... ), Morbig has the same behaviour (same error) but Dash rejects the script with:

Syntax error: end of file unexpected (expecting ")")

What do you think, should that be accepted or rejected in Morbig? I believe that in any case, it can be seen as a bug in Dash.

yurug commented 5 years ago

The first form is accepted by dash, bash and zsh. So I guess morbig should do the same, especially if we consider the following paragraph of the standard:

Within the backquoted style of command substitution, <backslash> shall retain its literal meaning, 
except when followed by: '$', '`', or <backslash>. The search for the matching backquote shall be 
satisfied by the first unquoted non-escaped backquote; during this search, if a non-escaped backquote 
is encountered within a shell comment, a here-document, an embedded command substitution of the
 $(command) form, or a quoted string, undefined results occur. A single-quoted or double-quoted string 
that begins, but does not end, within the "`...`" sequence produces undefined results.

which seems to state that this an unspecified situation.