hcl: fix scenario where infinite loop happens
This commit is contained in:
parent
a0a5d2873e
commit
9b5d9eb9b0
@ -164,6 +164,7 @@ func (x *hclLex) consumeComment(c rune) bool {
|
||||
// lexId lexes an identifier
|
||||
func (x *hclLex) lexId(yylval *hclSymType) int {
|
||||
var b bytes.Buffer
|
||||
first := true
|
||||
for {
|
||||
c := x.next()
|
||||
if c == lexEOF {
|
||||
@ -172,9 +173,16 @@ func (x *hclLex) lexId(yylval *hclSymType) int {
|
||||
|
||||
if !unicode.IsDigit(c) && !unicode.IsLetter(c) && c != '_' && c != '-' {
|
||||
x.backup()
|
||||
|
||||
if first {
|
||||
x.createErr("Invalid identifier")
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
first = false
|
||||
if _, err := b.WriteRune(c); err != nil {
|
||||
return lexEOF
|
||||
}
|
||||
|
@ -32,6 +32,10 @@ func TestLex(t *testing.T) {
|
||||
RIGHTBRACKET, lexEOF,
|
||||
},
|
||||
},
|
||||
{
|
||||
"old.hcl",
|
||||
[]int{IDENTIFIER, EQUAL, LEFTBRACE, STRING, lexEOF},
|
||||
},
|
||||
{
|
||||
"structure_basic.hcl",
|
||||
[]int{
|
||||
|
3
hcl/test-fixtures/old.hcl
Normal file
3
hcl/test-fixtures/old.hcl
Normal file
@ -0,0 +1,3 @@
|
||||
default = {
|
||||
"eu-west-1": "ami-b1cf19c6",
|
||||
}
|
Loading…
Reference in New Issue
Block a user