Problem/Motivation
In \Drupal\Core\Utility\UnroutedUrlAssembler::buildExternalUrl() we rebuild external URLs from their parts unnecessarily. PHP has lots of PHPism in the way it processes URLs but external systems don't all run PHP so we should not futz with external URLs unless we have to.
Steps to reproduce
See #1464244: Rewrite as URL adding equals sign to end of url. and #3038774: Url only outputs the last value of a query parameter
Proposed resolution
Only parse external URLs if we have to change something. This approach could be further improved in future issues by using PHP 8.5's new URI or URL classes and then only really messing with stuff when we have to change the query string. To quote the PHP 8.5 URI RFC the problems here are caused by
Query string parsing is a fuzzy area, since there are no established rules for parsing
Therefore I think avoiding any manipulation of external URLs is the best way to avoid bugs.
Remaining tasks
None
User interface changes
External URLs are not manipulated when used as menu links.
Introduced terminology
N/a
API changes
None
Data model changes
None
Release notes snippet
N/a
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | CleanShot 2025-10-27 at 10.41.55@2x.png | 45.05 KB | alexpott |
| #4 | CleanShot 2025-10-27 at 10.40.55@2x.png | 50.67 KB | alexpott |
Issue fork drupal-3554522
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3554522-11.2.x
changes, plain diff MR !13605
- 3554522-only-parse-and
changes, plain diff MR !13585
Comments
Comment #2
alexpottComment #4
alexpottProof this solves #1464244: Rewrite as URL adding equals sign to end of url....
Before
After
Comment #5
alexpottComment #6
alexpottComment #7
catchThis seems very sensible to me.
Comment #8
smustgrave commentedRan the test only here to verify coverage https://git.drupalcode.org/issue/drupal-3554522/-/jobs/7058053
Verified following the steps of the screenshots.
(I'm watching sports right now)
Added a link espn.com?test
Verified the link is rendering as espn.com?test=
Applied the MR
Now I just get espn.com?test
Appears to be working as described.
Comment #11
catchCommitted/pushed to 11.x and cherry-picked to 11.3.x, thanks!
Will need a backport if we want to put this into 11.2.x/10.6.x due to phpunit attributes changes. Marking fixed for now.
Comment #15
alexpottCreated an MR for 11.2.x / 10.x - I think we should consider backporting all the way because of the age and number of reports of the other issues.
Comment #18
catchCommitted/pushed to 11.2.x and cherry-picked to 10.6.x, thanks!