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

Issue fork drupal-3554522

Command icon 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:

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review

alexpott’s picture

alexpott’s picture

alexpott’s picture

Issue summary: View changes
catch’s picture

This seems very sensible to me.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Ran 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.

  • catch committed 3343b7c9 on 11.3.x
    Issue #3554522 by alexpott, smustgrave: Only parse and mess with the URI...

  • catch committed 4ea2a369 on 11.x
    Issue #3554522 by alexpott, smustgrave: Only parse and mess with the URI...
catch’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/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.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

alexpott’s picture

Version: 11.3.x-dev » 11.2.x-dev
Status: Fixed » Reviewed & tested by the community

Created 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.

  • catch committed 73d74826 on 11.2.x
    Issue #3554522 by alexpott: Only parse and mess with the URI in \Drupal\...

  • catch committed f7fc8ff2 on 10.6.x
    Issue #3554522 by alexpott: Only parse and mess with the URI in \Drupal\...
catch’s picture

Version: 11.2.x-dev » 10.6.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.2.x and cherry-picked to 10.6.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.