scanner: Report null bytes as errors, even at the end of file.
The formatter will append a newline at the end of file, causing the output of printer.Format() to be invalid.
This commit is contained in:
parent
a81aa7b5dd
commit
a5efd34964
@ -95,8 +95,7 @@ func (s *Scanner) next() rune {
|
||||
s.srcPos.Column = 0
|
||||
}
|
||||
|
||||
// If we see a null character with data left, then that is an error
|
||||
if ch == '\x00' && s.buf.Len() > 0 {
|
||||
if ch == '\x00' {
|
||||
s.err("unexpected null character (0x00)")
|
||||
return eof
|
||||
}
|
||||
|
@ -512,6 +512,8 @@ func TestError(t *testing.T) {
|
||||
|
||||
testError(t, "ab\x80", "1:3", "illegal UTF-8 encoding", token.IDENT)
|
||||
testError(t, "abc\xff", "1:4", "illegal UTF-8 encoding", token.IDENT)
|
||||
testError(t, "ab\x00", "1:3", "unexpected null character (0x00)", token.IDENT)
|
||||
testError(t, "ab\x00\n", "1:3", "unexpected null character (0x00)", token.IDENT)
|
||||
|
||||
testError(t, `"ab`+"\x80", "1:4", "illegal UTF-8 encoding", token.STRING)
|
||||
testError(t, `"abc`+"\xff", "1:5", "illegal UTF-8 encoding", token.STRING)
|
||||
|
Loading…
Reference in New Issue
Block a user