File tree Expand file tree Collapse file tree 2 files changed +19
-14
lines changed Expand file tree Collapse file tree 2 files changed +19
-14
lines changed Original file line number Diff line number Diff line change @@ -23,20 +23,18 @@ func nextValue(data []byte) int {
23
23
// Tries to find the end of string
24
24
// Support if string contains escaped quote symbols.
25
25
func stringEnd (data []byte ) int {
26
- i := 0
27
-
28
- for len (data ) > i {
29
- if data [i ] != '"' {
30
- i ++
31
- continue
32
- }
33
-
34
- // If it just escaped \", continue
35
- if i >= 1 && data [i - 1 ] == '\\' {
36
- i ++
37
- continue
38
- } else {
39
- return i + 1
26
+ escaped := false
27
+ for i , c := range data {
28
+ switch c {
29
+ case '\\' :
30
+ escaped = ! escaped
31
+ case '"' :
32
+ if ! escaped {
33
+ return i + 1
34
+ }
35
+ escaped = false
36
+ default :
37
+ escaped = false
40
38
}
41
39
}
42
40
Original file line number Diff line number Diff line change @@ -127,6 +127,13 @@ var getTests = []Test{
127
127
isFound : true ,
128
128
data : `\\\"` ,
129
129
},
130
+ Test {
131
+ desc : `unescaped backslash quote` ,
132
+ json : `{"a": "\\"}` ,
133
+ path : []string {"a" },
134
+ isFound : true ,
135
+ data : `\\` ,
136
+ },
130
137
Test {
131
138
desc : `unicode in JSON` ,
132
139
json : `{"a": "15°C"}` ,
You can’t perform that action at this time.
0 commit comments