fix(apiform): support primitive pointers in comma arrays - #119
Open
sylvesterkaczmarek wants to merge 1 commit into
Open
fix(apiform): support primitive pointers in comma arrays#119sylvesterkaczmarek wants to merge 1 commit into
sylvesterkaczmarek 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.
Summary
Dereference non-nil pointer/interface elements when encoding multipart arrays with
FormatComma, while preserving the existing empty-string representation for nil elements.Problem
internal/apiform.encodeArrayalready special-cases nil pointer/interface elements in comma-form arrays, but non-nil pointers are never dereferenced before the primitive-type switch.As a result, a valid primitive array such as:
fails with:
even though the pointed-to values are ordinary strings and the same encoder supports primitive values directly.
Fix
Unwrap pointer and interface layers before primitive comma serialization. If a nil value is encountered at any layer, keep the existing behavior of adding an empty comma element.
Complex non-primitive elements continue to return the same error as before.
Regression coverage
Added a focused multipart regression for
[]*string{&first, nil, &second}and verify it serializes as:Validation
The branch is based directly on current upstream
main(ee92673a416c0851a5fe8907a2453db7bd450633) and contains one commit touching onlyinternal/apiform/encoder.goplus focused regression coverage. Full Go test execution is left to repository CI.Risk
Low. The change only affects pointer/interface elements inside
FormatCommaarrays. Direct primitives, nil elements, complex-element rejection, and all other multipart array formats retain their existing behavior.