File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -162,15 +162,23 @@ func (l *lexer) acceptUntil(delims string) {
162162// rune contained in the provided string, unless that rune was
163163// escaped with a backslash
164164func (l * lexer ) acceptUntilUnescaped (delims string ) {
165+
165166 // Read until we hit an unescaped rune or the end of the input
167+ inEscape := false
166168 for {
167- if strings .ContainsRune (delims , l .next ()) && l .prev != '\\' {
169+ r := l .next ()
170+ if r == '\\' && ! inEscape {
171+ inEscape = true
172+ continue
173+ }
174+ if strings .ContainsRune (delims , r ) && ! inEscape {
168175 l .backup ()
169176 return
170177 }
171178 if l .cur == utf8 .RuneError {
172179 return
173180 }
181+ inEscape = false
174182 }
175183}
176184
Original file line number Diff line number Diff line change @@ -46,6 +46,27 @@ func TestLex(t *testing.T) {
4646 {`;` , typSemi },
4747 }},
4848
49+ {`json = "\\";` , []token {
50+ {`json` , typBare },
51+ {`=` , typEquals },
52+ {`"\\"` , typString },
53+ {`;` , typSemi },
54+ }},
55+
56+ {`json = "\\\\";` , []token {
57+ {`json` , typBare },
58+ {`=` , typEquals },
59+ {`"\\\\"` , typString },
60+ {`;` , typSemi },
61+ }},
62+
63+ {`json = "f\oo\\";` , []token {
64+ {`json` , typBare },
65+ {`=` , typEquals },
66+ {`"f\oo\\"` , typString },
67+ {`;` , typSemi },
68+ }},
69+
4970 {`json.value = "\u003c ;";` , []token {
5071 {`json` , typBare },
5172 {`.` , typDot },
You can’t perform that action at this time.
0 commit comments