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:
Mitchell Hashimoto 2015-06-23 21:34:40 -07:00
parent 513e04c400
commit 681623f4e1
5 changed files with 15 additions and 8 deletions

View File

@ -188,6 +188,14 @@ func TestDecode_interface(t *testing.T) {
},
},
},
{
"nested_block_comment.hcl",
false,
map[string]interface{}{
"bar": "value",
},
},
}
for _, tc := range cases {

View File

@ -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
}
}
}

View File

@ -6,7 +6,6 @@
/*
Baz
*/
*/
# Another

View File

@ -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]]

View File

@ -0,0 +1,5 @@
/*
foo = "bar/*"
*/
bar = "value"