Skip to content

edit: skip values in HasKey - #453

Merged
klauspost merged 1 commit into
tinylib:masterfrom
youdie006:haskey-skip-values
Sep 30, 2026
Merged

klauspost merged 1 commit into
tinylib:masterfrom
youdie006:haskey-skip-values

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

HasKey (msgp/edit.go:55-72) reads each map key with ReadStringZC but never skips the value after it, so the next iteration reads that value as a key. locate and locateKV call Skip(bts) after a non-matching key; HasKey does not.

For {"thing_one":"value_one","thing_two":2.0,"thing_three":{...}}:

call master this PR Locate finds it
HasKey("thing_one", raw) true true yes
HasKey("thing_three", raw) false true yes
HasKey("value_one", raw) true false no

The existing TestLocate only checks HasKey for the first key. TestHasKey covers first, middle and last keys, a string value, a key inside the nested map and a missing key; it fails on master and passes here. go test ./msgp, go vet, gofmt and the edit tests under GOARCH=386 pass on Go 1.26; I did not run ./_generated or Go 1.24/1.25.

Written with AI assistance (Claude); I have reviewed the change.

HasKey read each key but not the value after it, so on the next pass it
read the value as a key. A key after the first was missed and a string
value matched as a key. Skip the value as locate and locateKV do.
@klauspost
klauspost merged commit c3ec6a5 into tinylib:master Sep 30, 2026
4 checks passed
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.

2 participants