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
Comments
Comment #2
froboyAdding 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?
Comment #4
andyf commentedDuplicate: #3038774: Url only outputs the last value of a query parameter (Also related: #3038781: Output multiple values of a query param with repeating param name)