Skip to content

Bugfix: Utils::apiUrl renders query params as path segments - #248

Merged
roncodes merged 1 commit into
dev-v1.6.60from
fix/api-url-query-params
Aug 28, 2026
Merged

Bugfix: Utils::apiUrl renders query params as path segments#248
roncodes merged 1 commit into
dev-v1.6.60from
fix/api-url-query-params

Conversation

@roncodes

Copy link
Copy Markdown
Member

Problem

Utils::apiUrl() passed its $queryParams array straight through to Laravel's url($path, $parameters, $secure). Laravel's UrlGenerator::to() renders those extra parameters as rawurlencoded path segments with the keys discarded — it has never built a query string:

Utils::apiUrl('/api/user', ['id' => 1]);
// expected (per docblock): https://host/api/user?id=1
// actual:                  https://host/api/user/1

This silently broke every caller that passes query params. Known affected call sites:

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 — so UtilsTest asserted ?id=1 against the fake and passed.

Fix

  • Utils::apiUrl() now calls url($path, [], $secure) and appends the query string itself with http_build_query() (after the custom-port insertion, and with a & join if the path already carries a query string). Path-only callers are unaffected.
  • The test shim now mirrors UrlGenerator::to()'s real path-segment semantics, so the suite can no longer mask this divergence; the existing UtilsTest query-string assertions now pass because apiUrl itself builds the query string.

consoleUrl() was already correct (builds its own query string) and is untouched.

Verification

  • Ran the vendored Illuminate\Routing\UrlGenerator standalone to confirm the real url() behavior before the fix.
  • Full Pest suite: 1426 passed (10013 assertions), no failures.

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

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (04bf02e) to head (60a4a0c).

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     
Flag Coverage Δ
backend 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roncodes
roncodes merged commit 5c79f62 into dev-v1.6.60 Aug 28, 2026
5 checks passed
@roncodes
roncodes deleted the fix/api-url-query-params branch August 28, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant