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
|
// scanDigits scans a rune with the given base for n times. For example an
|
||||||
// octal notation \184 would yield in scanDigits(ch, 8, 3)
|
// octal notation \184 would yield in scanDigits(ch, 8, 3)
|
||||||
func (s *Scanner) scanDigits(ch rune, base, n int) rune {
|
func (s *Scanner) scanDigits(ch rune, base, n int) rune {
|
||||||
|
start := n
|
||||||
for n > 0 && digitVal(ch) < base {
|
for n > 0 && digitVal(ch) < base {
|
||||||
ch = s.next()
|
ch = s.next()
|
||||||
|
if ch == eof {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
n--
|
n--
|
||||||
}
|
}
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
s.err("illegal char escape")
|
s.err("illegal char escape")
|
||||||
}
|
}
|
||||||
|
|
||||||
// we scanned all digits, put the last non digit char back
|
if n != start {
|
||||||
|
// we scanned all digits, put the last non digit char back,
|
||||||
|
// only if we read anything at all
|
||||||
s.unread()
|
s.unread()
|
||||||
|
}
|
||||||
|
|
||||||
return ch
|
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) {
|
func TestComment(t *testing.T) {
|
||||||
testTokenList(t, tokenLists["comment"])
|
testTokenList(t, tokenLists["comment"])
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user