hcl/scanner: handle \"\\0 input properly
This commit is contained in:
parent
685b5f7416
commit
a6c7514d8d
@ -525,16 +525,25 @@ func (s *Scanner) scanEscape() rune {
|
||||
// scanDigits scans a rune with the given base for n times. For example an
|
||||
// octal notation \184 would yield in scanDigits(ch, 8, 3)
|
||||
func (s *Scanner) scanDigits(ch rune, base, n int) rune {
|
||||
start := n
|
||||
for n > 0 && digitVal(ch) < base {
|
||||
ch = s.next()
|
||||
if ch == eof {
|
||||
break
|
||||
}
|
||||
|
||||
n--
|
||||
}
|
||||
if n > 0 {
|
||||
s.err("illegal char escape")
|
||||
}
|
||||
|
||||
// we scanned all digits, put the last non digit char back
|
||||
s.unread()
|
||||
if n != start {
|
||||
// we scanned all digits, put the last non digit char back,
|
||||
// only if we read anything at all
|
||||
s.unread()
|
||||
}
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
|
@ -283,6 +283,11 @@ func TestPosition(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNullChar(t *testing.T) {
|
||||
s := New([]byte("\"\\0"))
|
||||
s.Scan() // Used to panic
|
||||
}
|
||||
|
||||
func TestComment(t *testing.T) {
|
||||
testTokenList(t, tokenLists["comment"])
|
||||
}
|
||||
@ -378,7 +383,7 @@ func TestRealExample(t *testing.T) {
|
||||
Main interface
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
network_interface {
|
||||
device_index = 1
|
||||
description = <<-EOF
|
||||
|
Loading…
Reference in New Issue
Block a user