parser: fix panicing for # style comments

HCL supports # style comments, which are 1 size len. We assumed that
it's always // or /* , which are two size length
This commit is contained in:
Fatih Arslan 2015-10-31 15:11:53 +03:00
parent 9b5083066a
commit 07cb426729

View File

@ -78,7 +78,7 @@ func (p *Parser) consumeComment() (comment *ast.Comment, endline int) {
endline = p.tok.Pos.Line endline = p.tok.Pos.Line
// count the endline if it's multiline comment, ie starting with /* // count the endline if it's multiline comment, ie starting with /*
if p.tok.Text[1] == '*' { if len(p.tok.Text) > 1 && p.tok.Text[1] == '*' {
// don't use range here - no need to decode Unicode code points // don't use range here - no need to decode Unicode code points
for i := 0; i < len(p.tok.Text); i++ { for i := 0; i < len(p.tok.Text); i++ {
if p.tok.Text[i] == '\n' { if p.tok.Text[i] == '\n' {