Skip to content

fix(ast): do not match unset slots when looking up the empty key - #1005

Open
sebxt wants to merge 1 commit into
bytedance:mainfrom
sebxt:fix/ast-get-empty-key-after-unset
Open

sebxt wants to merge 1 commit into
bytedance:mainfrom
sebxt:fix/ast-get-empty-key-after-unset

Conversation

@sebxt

@sebxt sebxt commented Oct 20, 2026

Copy link
Copy Markdown

What type of PR is this?

fix

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

fix(ast): 查找空字符串 key 时不再匹配已 Unset 的槽位

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en: Unset zeroes the removed pair, and a zeroed Pair{} has the key "". linkedPairs.Get compared only the key, so on {"a":1,"":2} after Unset("a"), Get("") matched the removed slot and reported the key as missing, and Set("", v) appended a duplicate "" pair ({"":2,"":3}).

The linear search now skips zeroed slots. A slot is treated as removed only when its hash is 0, its key is empty and its value is V_NONE; pairs built by NewPair (parser, Set) always have a non zero hash, so a real "" key, and a key explicitly set to an empty Node{} (relied on by TestNodeAny), still match.

Added TestGetEmptyKeyAfterUnset in ast/node_test.go; it fails on main and passes with this change. go test ./ast (default and with SONIC_USE_OPTDEC=1 SONIC_USE_FASTMAP=1 SONIC_ENCODER_USE_VM=1), go test ./issue_test ./generic_test . pass.

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

Fixes #1004

Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ast: Get("") misses an existing empty key after Unset, and Set("") then duplicates it

1 participant