From 54864211433d45cb780682431585b3e573b49e4a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 23 Jun 2015 21:38:11 -0700 Subject: [PATCH] hcl: multi-line comments aren't allowed to terminate with EOF --- decoder_test.go | 6 ++++++ hcl/lex.go | 9 ++++++++- test-fixtures/unterminated_block_comment.hcl | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test-fixtures/unterminated_block_comment.hcl 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