Skip to content

Commit e432328

Browse files
committed
scanner: Update prevPos even when returning utf8.RuneError.
The calling code will still call unread(), causing panics. This fixes the TestScanHeredocRegexpCompile() unit test.
1 parent 7d13b6e commit e432328

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

hcl/scanner/scanner.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,18 @@ func (s *Scanner) next() rune {
7474
return eof
7575
}
7676

77-
if ch == utf8.RuneError && size == 1 {
78-
s.srcPos.Column++
79-
s.srcPos.Offset += size
80-
s.lastCharLen = size
81-
s.err("illegal UTF-8 encoding")
82-
return ch
83-
}
84-
8577
// remember last position
8678
s.prevPos = s.srcPos
8779

8880
s.srcPos.Column++
8981
s.lastCharLen = size
9082
s.srcPos.Offset += size
9183

84+
if ch == utf8.RuneError && size == 1 {
85+
s.err("illegal UTF-8 encoding")
86+
return ch
87+
}
88+
9289
if ch == '\n' {
9390
s.srcPos.Line++
9491
s.lastLineLen = s.srcPos.Column

0 commit comments

Comments
 (0)