Skip to content

Commit

Permalink
syntax: fix hang with newlines in param exps
Browse files Browse the repository at this point in the history
Newlines are not skipped in some scenarios inside ${}, but we were
refusing to tokenize them into literals. This meant that we were forever
trying to get past those bytes.
  • Loading branch information
mvdan committed Nov 24, 2016
1 parent 5d4920c commit 456f78c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion syntax/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,9 @@ loop:
}
continue
case '\n':
if q != sglQuotes {
switch q {
case sglQuotes, paramExpRepl, paramExpExp:
default:
break loop
}
p.f.Lines = append(p.f.Lines, p.npos+1)
Expand Down
8 changes: 8 additions & 0 deletions syntax/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,14 @@ var bashTests = []errorCase{
"echo ${foo[]}",
`1:11: [ must be followed by an expression`,
},
{
"echo ${a/\n",
`1:6: reached EOF without matching ${ with }`,
},
{
"echo ${a-\n",
`1:6: reached EOF without matching ${ with }`,
},
{
"echo ${foo:",
`1:11: : must be followed by an expression`,
Expand Down

0 comments on commit 456f78c

Please sign in to comment.