diff --git a/decoder_test.go b/decoder_test.go index 52397f1..a71163b 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -196,6 +196,12 @@ func TestDecode_interface(t *testing.T) { "bar": "value", }, }, + + { + "unterminated_block_comment.hcl", + true, + nil, + }, } for _, tc := range cases { diff --git a/hcl/lex.go b/hcl/lex.go index c5493ae..c141659 100644 --- a/hcl/lex.go +++ b/hcl/lex.go @@ -125,7 +125,14 @@ func (x *hclLex) consumeComment(c rune) bool { c = x.next() if c == lexEOF { x.backup() - return true + if single { + // Single line comments can end with an EOF + return true + } + + // Multi-line comments must end with a */ + x.createErr(fmt.Sprintf("end of multi-line comment expected, got EOF")) + return false } // Single line comments continue until a '\n' diff --git a/test-fixtures/unterminated_block_comment.hcl b/test-fixtures/unterminated_block_comment.hcl new file mode 100644 index 0000000..c0ce34d --- /dev/null +++ b/test-fixtures/unterminated_block_comment.hcl @@ -0,0 +1,2 @@ +/* +Foo