in UnroutedUrlAssembler::buildExternalUrl
there is the following line:
$options['query'] = NestedArray::mergeDeep($parsed['query'], $options['query']);
This results in the following issue:
- I have a link field
- User enters a link like this: http://www.example.com/cgi-bin/foo.cgi?12345=67890
- Drupal outputs the link like this: http://www.example.com/cgi-bin/foo.cgi?0=67890
The problem is caused by NestedArray::mergeDeep()
not preserving array integer keys during its work. As far as I can tell, the solution is to simply use a different merge function: NestedArray::mergeDeepArray()
has an additional parameter that allows to specify that array integer keys should be preserved.
So, in effect the line cited further up should become this:
$options['query'] = NestedArray::mergeDeepArray(array($parsed['query'], $options['query']), TRUE);
FWIW, from reading the comments in another issue (one, two) it appears that the merge function call was added in issue 2955685.
Comment | File | Size | Author |
---|---|---|---|
#7 | 3007243-UnroutedUrlAssembler_buildExternalUrl-preserve_original_query-3.patch | 1.18 KB | Josh Waihi |
Comments
Comment #4
Josh Waihi CreditAttribution: Josh Waihi commentedPerhaps similarly, buildExternalUrl does not preserve how keys are described.
See the below output from drush php where "foo[]" is replaced with "foo[0]".
Drupal shouldn't really have the right to reformat external URLs as it can't guarantee the external service being linked to will interpret Drupal's reformatting correctly.
Comment #5
Josh Waihi CreditAttribution: Josh Waihi as a volunteer and commentedHere is a workaround patch that preserves the original query from the external URI.
Comment #6
Josh Waihi CreditAttribution: Josh Waihi as a volunteer and commentedAttached new view that ensures $original_query doesn't accidently because the $uri itself.
Comment #7
Josh Waihi CreditAttribution: Josh Waihi as a volunteer and commentedOkay this one should work as intended.
Comment #12
mstrelan CreditAttribution: mstrelan at PreviousNext commentedThis looks like it was fixed in #3027763: UnroutedUrlAssembler removes query params array item key in buildExternalUrl(). Closing as a duplicate.