Fix serialization of array values in query string parameters#46
Open
aivus wants to merge 1 commit into
Open
Conversation
RequestFactory cast every query placeholder value to string, so an array value produced the literal "Array" in the request URI. Serialize arrays with http_build_query() instead, expanding them to bracket syntax (param[0]=a¶m[1]=b). Empty arrays drop the parameter entirely, with leftover query separators cleaned up. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
RequestFactory::getRequestUri()substitutes every query placeholder withurlencode((string)$value). When a request DTO getter returns an array (e.g.getCategories(): ?arrayfor an endpoint path like/list?categories={categories}), the string cast produces the literal valueArrayin the request URI (plus a PHP notice), so array query parameters cannot be sent at all.Fix
http_build_query(), replacing the wholename={placeholder}pair. This expands to bracket syntax (categories%5B0%5D=a&categories%5B1%5D=b), which PHP servers natively parse back into arrays via$request->query->all().normalizeQueryString()helper cleans up leftover&&/?&/ trailing separators.Tests
Added
RequestFactoryTestcases covering: multi-value arrays expanding to bracket syntax, urlencoding of array items, empty arrays being dropped (first, middle, and only-parameter positions, including no trailing?). Full suite: 95 tests, 255 assertions, green on PHP 7.4.🤖 Generated with Claude Code