hcl/parser: fix broken parsing of: "v=/\n[,"

This commit is contained in:
Mitchell Hashimoto 2016-06-21 13:21:48 -07:00
parent 6816a5c3fb
commit 50042432b0
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 5 additions and 1 deletions

View File

@ -331,7 +331,7 @@ func (p *Parser) listType() (*ast.ListType, error) {
// get next list item or we are at the end
// do a look-ahead for line comment
p.scan()
if p.lineComment != nil {
if p.lineComment != nil && len(l.List) > 0 {
lit, ok := l.List[len(l.List)-1].(*ast.LiteralType)
if ok {
lit.LineComment = p.lineComment

View File

@ -343,9 +343,13 @@ func TestParse_inline(t *testing.T) {
{"o{{}}", true},
{"t t e d N{{}}", true},
{"t t e d{{}}", true},
{"N{}N{{}}", true},
{"v\nN{{}}", true},
{"v=/\n[,", true},
}
for _, tc := range cases {
t.Logf("Testing: %q", tc.Value)
ast, err := Parse([]byte(tc.Value))
if (err != nil) != tc.Err {
t.Fatalf("Input: %q\n\nError: %s\n\nAST: %s", tc.Value, err, spew.Sdump(ast))