2
0
Fork 0
mirror of https://github.com/ii64/sonic.git synced 2026-06-20 16:45:22 +08:00

fix: match empty string in path (#387)

This commit is contained in:
liu 2023-03-19 19:21:40 +08:00 committed by GitHub
parent 8dbcce341b
commit 114b8168d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 877 additions and 836 deletions

View file

@ -123,6 +123,7 @@ func TestExportErrNotExist(t *testing.T) {
// {`{"a":null}`, []interface{}{"a", 0}, ErrNotExist},
// {`{"a":null}`, []interface{}{"a", "b", 0}, ErrNotExist},
{`{"":{"b":123}}`, []interface{}{"b"}, ErrNotExist},
{`{"":{"b":123}}`, []interface{}{"", ""}, ErrNotExist},
{`{"a":{"b":123}}`, []interface{}{"b"}, ErrNotExist},
{`{"a":{"b":123}}`, []interface{}{"a", "c"}, ErrNotExist},
{`{"a":{"c": null, "b":{}}}`, []interface{}{"a", "b", "c"}, ErrNotExist},
@ -209,6 +210,8 @@ func TestSearcher_GetByPathSingle(t *testing.T) {
{`"abc"`, Path{}, "abc", Ok},
{`"a\"\\bc"`, Path{}, "a\"\\bc", Ok},
{`{"a":1}`, Path{"a"}, 1.0, Ok},
{`{"":1}`, Path{""}, 1.0, Ok},
{`{"":{"":1}}`, Path{"", ""}, 1.0, Ok},
{`[1,2,3]`, Path{0}, 1.0, Ok},
{`[1,2,3]`, Path{1}, 2.0, Ok},
{`[1,2,3]`, Path{2}, 3.0, Ok},

File diff suppressed because it is too large Load diff

View file

@ -9,7 +9,7 @@ package avx
func __native_entry__() uintptr
var (
_subr__f32toa = __native_entry__() + 28640
_subr__f32toa = __native_entry__() + 28672
_subr__f64toa = __native_entry__() + 448
_subr__get_by_path = __native_entry__() + 25568
_subr__html_escape = __native_entry__() + 9296
@ -24,8 +24,8 @@ var (
_subr__u64toa = __native_entry__() + 3856
_subr__unquote = __native_entry__() + 6928
_subr__validate_one = __native_entry__() + 22368
_subr__validate_utf8 = __native_entry__() + 27392
_subr__validate_utf8_fast = __native_entry__() + 28064
_subr__validate_utf8 = __native_entry__() + 27424
_subr__validate_utf8_fast = __native_entry__() + 28096
_subr__value = __native_entry__() + 12480
_subr__vnumber = __native_entry__() + 16256
_subr__vsigned = __native_entry__() + 17872

File diff suppressed because it is too large Load diff

View file

@ -9,7 +9,7 @@ package avx2
func __native_entry__() uintptr
var (
_subr__f32toa = __native_entry__() + 34624
_subr__f32toa = __native_entry__() + 34656
_subr__f64toa = __native_entry__() + 736
_subr__get_by_path = __native_entry__() + 29232
_subr__html_escape = __native_entry__() + 10944
@ -24,8 +24,8 @@ var (
_subr__u64toa = __native_entry__() + 4144
_subr__unquote = __native_entry__() + 8336
_subr__validate_one = __native_entry__() + 26064
_subr__validate_utf8 = __native_entry__() + 31056
_subr__validate_utf8_fast = __native_entry__() + 32016
_subr__validate_utf8 = __native_entry__() + 31088
_subr__validate_utf8_fast = __native_entry__() + 32048
_subr__value = __native_entry__() + 15472
_subr__vnumber = __native_entry__() + 19280
_subr__vsigned = __native_entry__() + 20896

File diff suppressed because it is too large Load diff

View file

@ -9,7 +9,7 @@ package sse
func __native_entry__() uintptr
var (
_subr__f32toa = __native_entry__() + 29264
_subr__f32toa = __native_entry__() + 29312
_subr__f64toa = __native_entry__() + 448
_subr__get_by_path = __native_entry__() + 26208
_subr__html_escape = __native_entry__() + 9360
@ -24,8 +24,8 @@ var (
_subr__u64toa = __native_entry__() + 3840
_subr__unquote = __native_entry__() + 6992
_subr__validate_one = __native_entry__() + 22576
_subr__validate_utf8 = __native_entry__() + 28032
_subr__validate_utf8_fast = __native_entry__() + 28704
_subr__validate_utf8 = __native_entry__() + 28080
_subr__validate_utf8_fast = __native_entry__() + 28752
_subr__value = __native_entry__() + 12560
_subr__vnumber = __native_entry__() + 16416
_subr__vsigned = __native_entry__() + 18064

View file

@ -1781,6 +1781,12 @@ static always_inline long match_key(const GoString *src, long *p, const GoString
/* compare non-escaped strings */
if (likely(v == -1 || v > se)) {
long sn = se - si - 1;
// check empty keys
if (!sn && !key.len) {
return true;
}
return sn == key.len && xmemcmpeq(src->buf + si, key.buf, key.len);
}