hcl: don't allow nested comments
This copies C's behavior and disallows nested block comments. It ignores a new /* within an existing block comment and ends at the first */
This commit is contained in:
parent
513e04c400
commit
681623f4e1
@ -188,6 +188,14 @@ func TestDecode_interface(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
"nested_block_comment.hcl",
|
||||
false,
|
||||
map[string]interface{}{
|
||||
"bar": "value",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
@ -149,18 +149,13 @@ func (x *hclLex) consumeComment(c rune) bool {
|
||||
case '*':
|
||||
c = x.next()
|
||||
if c == '/' {
|
||||
nested--
|
||||
return true
|
||||
} else {
|
||||
x.backup()
|
||||
}
|
||||
default:
|
||||
// Continue
|
||||
}
|
||||
|
||||
// If we're done with the comment, return!
|
||||
if nested == 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
/*
|
||||
Baz
|
||||
*/
|
||||
*/
|
||||
|
||||
# Another
|
||||
|
||||
|
@ -9,7 +9,7 @@ const _ValueType_name = "ValueTypeUnknownValueTypeFloatValueTypeIntValueTypeStri
|
||||
var _ValueType_index = [...]uint8{0, 16, 30, 42, 57, 70, 82, 95, 110}
|
||||
|
||||
func (i ValueType) String() string {
|
||||
if i+1 >= ValueType(len(_ValueType_index)) {
|
||||
if i >= ValueType(len(_ValueType_index)-1) {
|
||||
return fmt.Sprintf("ValueType(%d)", i)
|
||||
}
|
||||
return _ValueType_name[_ValueType_index[i]:_ValueType_index[i+1]]
|
||||
|
5
test-fixtures/nested_block_comment.hcl
Normal file
5
test-fixtures/nested_block_comment.hcl
Normal file
@ -0,0 +1,5 @@
|
||||
/*
|
||||
foo = "bar/*"
|
||||
*/
|
||||
|
||||
bar = "value"
|
Loading…
Reference in New Issue
Block a user