in UnroutedUrlAssembler::buildExternalUrl there is the following line:

$options['query'] = NestedArray::mergeDeep($parsed['query'], $options['query']);

This results in the following issue:

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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

herzbube created an issue. See original summary.

Version: 8.6.1 » 8.6.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.6.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Josh Waihi’s picture

Perhaps similarly, buildExternalUrl does not preserve how keys are described.
See the below output from drush php where "foo[]" is replaced with "foo[0]".

>>> $url = \Drupal\Core\Url::fromUri('https://example.com/?foo[]=bar');
=> Drupal\Core\Url {#5156}
>>> $url->toUriString();
=> "https://example.com/?foo[]=bar"
>>> $url->toString();
=> "https://example.com/?foo%5B0%5D=bar"
>>> $url = \Drupal\Core\Url::fromUri('https://example.com/?foo%5B0%5D=bar');
=> Drupal\Core\Url {#6217}
>>> $url = \Drupal\Core\Url::fromUri('https://example.com/?foo%5B%5D=bar');
=> Drupal\Core\Url {#1517}
>>> $url->toUriString();
=> "https://example.com/?foo%5B%5D=bar"
>>> $url->toString();
=> "https://example.com/?foo%5B0%5D=bar"
>>> $url->getUri();
=> "https://example.com/?foo%5B%5D=bar"

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.

Josh Waihi’s picture

Here is a workaround patch that preserves the original query from the external URI.

Josh Waihi’s picture

Attached new view that ensures $original_query doesn't accidently because the $uri itself.

Josh Waihi’s picture

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mstrelan’s picture

Status: Active » Closed (duplicate)
Issue tags: -url, -external URL, -query params +Bug Smash Initiative