Skip to content

Commit

Permalink
fix: match empty string in path (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuq19 authored Mar 19, 2023
1 parent 8dbcce3 commit 114b816
Show file tree
Hide file tree
Showing 8 changed files with 853 additions and 812 deletions.
3 changes: 3 additions & 0 deletions ast/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down
582 changes: 297 additions & 285 deletions internal/native/avx/native_amd64.s

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/native/avx/native_subr_amd64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

472 changes: 240 additions & 232 deletions internal/native/avx2/native_amd64.s

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/native/avx2/native_subr_amd64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

584 changes: 298 additions & 286 deletions internal/native/sse/native_amd64.s

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/native/sse/native_subr_amd64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions native/scanning.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 114b816

Please sign in to comment.