fix(apiquery): reject non-string map keys - #88
Open
sylvesterkaczmarek wants to merge 2 commits into
Open
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.
Summary
Fail clearly when URL-query encoding receives a map whose keys are not strings, instead of serializing reflection placeholder text into parameter names.
Fixes #87.
Problem
internal/apiquery.encodeMapcurrently assumes every map key is a string and calls:without checking the key kind.
For a non-string
reflect.Value,String()is not a conversion of the underlying key. It returns reflection's diagnostic representation. A value such as:can therefore proceed into request encoding with a malformed implementation-specific query key instead of failing at the serialization boundary.
Root cause
The map encoder relies on a string-key invariant that it never validates.
The sibling multipart/form encoder already rejects non-string map keys explicitly, so the two request encoders currently disagree on the same unsupported input shape.
Fix
Inspect each map key before using it:
String-key behavior and nested query formatting remain unchanged.
Regression coverage
Added focused tests proving:
map[int]string{1: "one"}returns a clear error and no query values;map[string]stringcontinues to encode normally.The invalid-map case exercises the public
Marshalpath rather than calling the internal encoder directly.Validation
The branch is based directly on upstream
mainatd082a010f7c6cacf407d8a1581446a7857f9f1bband is not behind it.Production diff: 5 additions and 1 deletion in
internal/apiquery/encoder.go, plus one focused regression file.Full repository validation is left to the repository's GitHub Actions checks.
Risk
Low. The only newly rejected inputs are map shapes that cannot preserve their key semantics in URL query parameter names. Existing string-key maps, arrays, primitives, and nesting formats are unchanged.