Skip to content

Commit 73fde59

Browse files
committed
scanner: Add unit test triggering a panic in scanHeredoc().
``` panic: regexp: Compile("[[:space:]]*<\xc8\\z"): error parsing regexp: invalid UTF-8: `�\z` goroutine 32 [running]: testing.tRunner.func1(0xc4200cae10) /usr/lib/google-golang/src/testing/testing.go:742 +0x29d panic(0x507a00, 0xc420290690) /usr/lib/google-golang/src/runtime/panic.go:505 +0x229 regexp.MustCompile(0xc420289e10, 0x10, 0xc420087680) /usr/lib/google-golang/src/regexp/regexp.go:240 +0x171 github.com/hashicorp/hcl/hcl/scanner.(*Scanner).scanHeredoc(0xc4200878c0) gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:444 +0x3a9 github.com/hashicorp/hcl/hcl/scanner.(*Scanner).Scan(0xc4200878c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:186 +0x3e5 ```
1 parent b1738d9 commit 73fde59

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

hcl/scanner/scanner_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,3 +589,22 @@ func countNewlines(s string) int {
589589
}
590590
return n
591591
}
592+
593+
func TestScanHeredocRegexpCompile(t *testing.T) {
594+
cases := []string{
595+
"0\xe1\n<<ȸ\nhello\nworld\nȸ",
596+
}
597+
598+
for _, c := range cases {
599+
s := New([]byte(c))
600+
fmt.Printf("START %q\n", c)
601+
602+
for {
603+
tok := s.Scan()
604+
if tok.Type == token.EOF {
605+
break
606+
}
607+
t.Logf("s.Scan() = %s", tok)
608+
}
609+
}
610+
}

0 commit comments

Comments
 (0)