Skip to content

Commit 91ac968

Browse files
authored
fix issue 188 (#192)
**Description**: This pr fix issue #188. If `findKeyStart` meets a `[` or `{`, it should not add i with `blockEnd`’s return value directly because it may return -1 if it did not find the close symbol
1 parent 1a29609 commit 91ac968

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

parser.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,15 @@ func findKeyStart(data []byte, key string) (int, error) {
9898
}
9999

100100
case '[':
101-
i = blockEnd(data[i:], data[i], ']') + i
101+
end := blockEnd(data[i:], data[i], ']')
102+
if end != -1 {
103+
i = i + end
104+
}
102105
case '{':
103-
i = blockEnd(data[i:], data[i], '}') + i
106+
end := blockEnd(data[i:], data[i], '}')
107+
if end != -1 {
108+
i = i + end
109+
}
104110
}
105111
i++
106112
}

parser_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ var deleteTests = []DeleteTest{
185185
path: []string{"b"},
186186
data: `{"a": "1" , "c": 3}`,
187187
},
188+
{
189+
desc: "Issue #188: infinite loop in Delete",
190+
json: `^_�^C^A^@[`,
191+
path: []string{""},
192+
data: `^_�^C^A^@[`,
193+
},
194+
{
195+
desc: "Issue #188: infinite loop in Delete",
196+
json: `^_�^C^A^@{`,
197+
path: []string{""},
198+
data: `^_�^C^A^@{`,
199+
},
188200
}
189201

190202
var setTests = []SetTest{

0 commit comments

Comments
 (0)