Bugfix: Utils::apiUrl renders query params as path segments - #248
Merged
Conversation
Laravel's url() helper renders its second argument as rawurlencoded path
segments with keys discarded, so apiUrl('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/api/user', ['id' => 1]) produced
https://host/api/user/1 instead of the documented ?id=1. Build the query
string with http_build_query after the port insertion instead.
Also correct the test bootstrap's url() shim to mirror the real
UrlGenerator::to() path-segment semantics, which had been masking the
divergence in UtilsTest.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev-v1.6.60 #248 +/- ##
===============================================
Coverage 100.00% 100.00%
- Complexity 6732 6734 +2
===============================================
Files 397 397
Lines 22468 22470 +2
===============================================
+ Hits 22468 22470 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Utils::apiUrl()passed its$queryParamsarray straight through to Laravel'surl($path, $parameters, $secure). Laravel'sUrlGenerator::to()renders those extra parameters as rawurlencoded path segments with the keys discarded — it has never built a query string:This silently broke every caller that passes query params. Known affected call sites:
storefront— the QPay payment callback URL (CheckoutController.php:768) came out as.../capture-qpay/checkout_xxx, which matches no route, so QPay's server-side payment notification 404s (context: Bugfix: Patch QPay service callback URL, and ensure callbackUrl is pr… storefront#90).solid— the OIDC complete-registration URL (SolidIdentity.php:74).Why tests never caught it
The Pest bootstrap runs without booting Laravel and defines its own fallback
url()shim, which implemented the query-string behavior the docblock promises rather than the path-segment behavior Laravel actually has — soUtilsTestasserted?id=1against the fake and passed.Fix
Utils::apiUrl()now callsurl($path, [], $secure)and appends the query string itself withhttp_build_query()(after the custom-port insertion, and with a&join if the path already carries a query string). Path-only callers are unaffected.UrlGenerator::to()'s real path-segment semantics, so the suite can no longer mask this divergence; the existingUtilsTestquery-string assertions now pass becauseapiUrlitself builds the query string.consoleUrl()was already correct (builds its own query string) and is untouched.Verification
Illuminate\Routing\UrlGeneratorstandalone to confirm the realurl()behavior before the fix.