Skip to content

Commit 7f23329

Browse files
committed
Enhance lexer and test cases to handle null characters in strings
1 parent ee7829b commit 7f23329

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pkg/engine/op_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ for x in [1,2,3 ] {
8383
break
8484
}
8585
86+
x = "\u0000"
87+
x = "\u0000zzzz"
88+
x = "zzz\u0000"
89+
8690
add_key(len1, len([12,2]))
8791
add_key(len2, len("123"))
8892

pkg/parser/lex.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,12 @@ func lexEscape(l *Lexer) stateFn {
567567
l.errorf("escape sequence is an invalid Unicode code point")
568568
}
569569

570+
// Backup one position since we've read the character after the escape sequence
571+
// (which should be handled by lexString, e.g., the closing quote)
572+
if ch != eof {
573+
l.backup()
574+
}
575+
570576
log.Debugf("get number %d", x)
571577
return lexString
572578
}
@@ -677,7 +683,6 @@ func (l *Lexer) acceptRun(valid string) {
677683
func (l *Lexer) NextItem(itemp *Item) {
678684
l.scannedItem = false
679685
l.itemp = itemp
680-
681686
if l.state != nil {
682687
for !l.scannedItem {
683688
l.state = l.state(l)

0 commit comments

Comments
 (0)