Merge pull request #135 from hashicorp/b-null
hcl/scanner: handle \"\\0 input properly
This commit is contained in:
commit
d7ee01d2a7
@ -525,16 +525,27 @@ 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 {
|
||||||
|
// If we see an EOF, we halt any more scanning of digits
|
||||||
|
// immediately.
|
||||||
|
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 {
|
||||||
s.unread()
|
// we scanned all digits, put the last non digit char back,
|
||||||
|
// only if we read anything at all
|
||||||
|
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"])
|
||||||
}
|
}
|
||||||
@ -378,7 +383,7 @@ func TestRealExample(t *testing.T) {
|
|||||||
Main interface
|
Main interface
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
network_interface {
|
network_interface {
|
||||||
device_index = 1
|
device_index = 1
|
||||||
description = <<-EOF
|
description = <<-EOF
|
||||||
|
Loading…
x
Reference in New Issue
Block a user