Fixed hang when comment was on the last line of the file

This commit is contained in:
Eljas Alakulppi 2015-11-29 00:20:41 +02:00
parent f0ca992551
commit 2ec27b6be2
3 changed files with 9 additions and 2 deletions

View File

@ -231,6 +231,10 @@ func TestParse(t *testing.T) {
"comment.hcl", "comment.hcl",
false, false,
}, },
{
"comment_lastline.hcl",
false,
},
{ {
"comment_single.hcl", "comment_single.hcl",
false, false,

View File

@ -0,0 +1 @@
#foo

View File

@ -224,10 +224,12 @@ func (s *Scanner) scanComment(ch rune) {
// single line comments // single line comments
if ch == '#' || (ch == '/' && s.peek() != '*') { if ch == '#' || (ch == '/' && s.peek() != '*') {
ch = s.next() ch = s.next()
for ch != '\n' && ch >= 0 { for ch != '\n' && ch >= 0 && ch != eof {
ch = s.next() ch = s.next()
} }
s.unread() if ch != eof && ch >= 0 {
s.unread()
}
return return
} }