Problem/Motivation

Drupal doesn't handle external URLs that have repeated key/value pairs in the query. This is causing real-world problems for a client integrating with a system called Daxko that seems to use such URLs.

As far as I can tell there's no RFC that dictates that format of parameters within a query string, so it seems to me the safe thing to do would be to preserve external URL query strings in their entirety. That said I noticed in a related (but separate I think) issue, #2885351: Query string duplications, that there are tests being written to verify the current behavior, so I'm wondering if I'm missing something!

Steps to reproduce

$ drush ev "print \Drupal\Core\Url::fromUri('https://example.com/?a=1&a=2')->toString() . PHP_EOL"
https://example.com/?a=2

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

AndyF created an issue. See original summary.

froboy’s picture

Adding some possibly related tickets.

As some other folks have mentioned, this seems to be an underlying PHP issue, I think with parse_str as called in Url::fromUri:

parse_str($uri_parts['query'], $uri_query);

There's a "solution" on php.net explaining how a "proper_parse_str" might function.

I guess we'd need to...
- decide if Drupal should support duplicate query strings
- (if yes...) write some tests
- implement "proper_parse_str" somewhere
- replace "parse_str" with "proper_parse_str" in Url::fromUri and like... everywhere?

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.