Fix empty string operator not matching

fixes #246
This commit is contained in:
tidwall 2021-10-25 07:11:04 -07:00
parent 8ac7a764ca
commit 0b52f9a361
2 changed files with 13 additions and 1 deletions

View File

@ -761,7 +761,7 @@ func parseArrayPath(path string) (r arrayPathResult) {
// bad query, end now
break
}
if len(value) > 2 && value[0] == '"' &&
if len(value) >= 2 && value[0] == '"' &&
value[len(value)-1] == '"' {
value = value[1 : len(value)-1]
if vesc {

View File

@ -2261,3 +2261,15 @@ func TestNaNInf(t *testing.T) {
})
}
func TestEmptyValueQuery(t *testing.T) {
// issue: https://github.com/tidwall/gjson/issues/246
assert(t, Get(
`["ig","","tw","fb","tw","ig","tw"]`,
`#(!="")#`).Raw ==
`["ig","tw","fb","tw","ig","tw"]`)
assert(t, Get(
`["ig","","tw","fb","tw","ig","tw"]`,
`#(!=)#`).Raw ==
`["ig","tw","fb","tw","ig","tw"]`)
}