fix: case-insensitive key match for structs with more than 16 fields (#427) - #608
Open
chiliec wants to merge 1 commit into
Open
fix: case-insensitive key match for structs with more than 16 fields (#427)#608chiliec wants to merge 1 commit into
chiliec wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #427.
Structs with more than 16 fields didn't get their values populated when a JSON key differed in case from the Go field name (e.g.
someField1forSomeField1). Structs with 16 or fewer fields worked fine, andencoding/jsonmatches case-insensitively in both cases, so the two decode paths disagreed.Fix
The bitmap-optimized key decoder (used for ≤16 fields) already matches keys case-insensitively. The non-optimized fallback path (
decodeKey/decodeKeyStream, taken for >16 fields) only did an exactfieldMap[k]lookup.fieldMapis already populated with lowercased key aliases at compile time, so falling back tofieldMap[strings.ToLower(k)]on a miss restores parity with the optimized path and withencoding/json.Tests
Added
TestIssue427indecode_test.gocovering bothUnmarshaland the streamingDecoder.Validation
RED→GREEN (reverting only the source change):
Full suite green, gofmt clean:
Happy to adjust.