Skip to content

Commit

Permalink
syntax: error on unclosed nested backquotes
Browse files Browse the repository at this point in the history
Nested backquote command substitutions use backslashes, such as:

	` \`echo foo\` `

When looking for the closing backquote, we didn't error if the number of
backslashes in the closing token was lower than expected. Do that, and
add a regression test.

Fixes mvdan#349.
  • Loading branch information
mvdan committed Jan 19, 2019
1 parent 6157fb8 commit 4c45382
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions syntax/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,11 @@ func (p *Parser) wordPart() WordPart {

p.next()
cs.StmtList = p.stmtList()
if p.tok == bckQuote && p.lastBquoteEsc < p.openBquotes-1 {
// e.g. found ` before the nested backquote \` was closed.
p.tok = _EOF
p.quoteErr(cs.Pos(), bckQuote)
}
p.postNested(old)
p.openBquotes--
cs.Right = p.pos
Expand Down
4 changes: 4 additions & 0 deletions syntax/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,10 @@ var shellTests = []errorCase{
in: "`\"`",
common: "1:3: reached EOF without closing quote `",
},
{
in: "`\\```",
common: "1:2: reached EOF without closing quote `",
},
{
in: "`{\n`",
common: "1:2: reached ` without matching { with }",
Expand Down

0 comments on commit 4c45382

Please sign in to comment.