Skip to content

Commit

Permalink
Merge pull request hashicorp#239 from octo/scanner
Browse files Browse the repository at this point in the history
scanner: Don't call unread() after reading EOF.
  • Loading branch information
mitchellh committed Apr 3, 2018
2 parents c247bd0 + 23ed7ba commit 061bf37
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hcl/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ func (s *Scanner) scanDigits(ch rune, base, n int) rune {
s.err("illegal char escape")
}

if n != start {
if n != start && ch != eof {
// we scanned all digits, put the last non digit char back,
// only if we read anything at all
s.unread()
Expand Down
28 changes: 27 additions & 1 deletion hcl/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,14 +593,40 @@ func countNewlines(s string) int {
return n
}

func TestScanDigitsUnread(t *testing.T) {
cases := []string{
"M=0\"\\00",
"M=\"\\00",
"\"\\00",
"M=[\"\\00",
"U{\"\\00",
"\"\n{}#\n\"\\00",
"M=[[\"\\00",
"U{d=0\"\\U00",
"#\n\"\\x00",
"m=[[[\"\\00",
}

for _, c := range cases {
s := New([]byte(c))

for {
tok := s.Scan()
if tok.Type == token.EOF {
break
}
t.Logf("s.Scan() = %s", tok)
}
}
}

func TestScanHeredocRegexpCompile(t *testing.T) {
cases := []string{
"0\xe1\n<<ȸ\nhello\nworld\nȸ",
}

for _, c := range cases {
s := New([]byte(c))
fmt.Printf("START %q\n", c)

for {
tok := s.Scan()
Expand Down

0 comments on commit 061bf37

Please sign in to comment.