diff core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php @ 16:c2387f117808

Routine composer update
author Chris Cannam
date Tue, 10 Jul 2018 15:07:59 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
line wrap: on
line diff
--- a/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php	Thu Apr 26 11:26:54 2018 +0100
+++ b/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php	Tue Jul 10 15:07:59 2018 +0100
@@ -2,6 +2,7 @@
 
 namespace Drupal\Core\Utility;
 
+use Drupal\Component\Utility\NestedArray;
 use Drupal\Component\Utility\UrlHelper;
 use Drupal\Core\GeneratedUrl;
 use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
@@ -69,13 +70,18 @@
    */
   protected function buildExternalUrl($uri, array $options = [], $collect_bubbleable_metadata = FALSE) {
     $this->addOptionDefaults($options);
-    // Split off the fragment.
-    if (strpos($uri, '#') !== FALSE) {
-      list($uri, $old_fragment) = explode('#', $uri, 2);
-      // If $options contains no fragment, take it over from the path.
-      if (isset($old_fragment) && !$options['fragment']) {
-        $options['fragment'] = '#' . $old_fragment;
-      }
+    // Split off the query & fragment.
+    $parsed = UrlHelper::parse($uri);
+    $uri = $parsed['path'];
+
+    $parsed += ['query' => []];
+    $options += ['query' => []];
+
+    $options['query'] = NestedArray::mergeDeep($parsed['query'], $options['query']);
+    ksort($options['query']);
+
+    if ($parsed['fragment'] && !$options['fragment']) {
+      $options['fragment'] = '#' . $parsed['fragment'];
     }
 
     if (isset($options['https'])) {
@@ -88,7 +94,7 @@
     }
     // Append the query.
     if ($options['query']) {
-      $uri .= (strpos($uri, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($options['query']);
+      $uri .= '?' . UrlHelper::buildQuery($options['query']);
     }
     // Reassemble.
     $url = $uri . $options['fragment'];