Skip to content

Commit ec2ba18

Browse files
committed
scanner: Fail if U+E123 is found in input.
This (invalid) Unicode codepoint is used by the printer package to fix up the indentation of generated files. If this codepoint is present in the input, the package gets confused and removes more than it should, producing unparsable output.
1 parent a5efd34 commit ec2ba18

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

hcl/scanner/scanner.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ func (s *Scanner) next() rune {
100100
return eof
101101
}
102102

103+
if ch == '\uE123' {
104+
s.err("unicode code point U+E123 reserved for internal use")
105+
return utf8.RuneError
106+
}
107+
103108
// debug
104109
// fmt.Printf("ch: %q, offset:column: %d:%d\n", ch, s.srcPos.Offset, s.srcPos.Column)
105110
return ch

hcl/scanner/scanner_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ func TestScan_crlf(t *testing.T) {
509509
func TestError(t *testing.T) {
510510
testError(t, "\x80", "1:1", "illegal UTF-8 encoding", token.ILLEGAL)
511511
testError(t, "\xff", "1:1", "illegal UTF-8 encoding", token.ILLEGAL)
512+
testError(t, "\uE123", "1:1", "unicode code point U+E123 reserved for internal use", token.ILLEGAL)
512513

513514
testError(t, "ab\x80", "1:3", "illegal UTF-8 encoding", token.IDENT)
514515
testError(t, "abc\xff", "1:4", "illegal UTF-8 encoding", token.IDENT)

0 commit comments

Comments
 (0)