Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / lib / Drupal / Core / Utility / UnroutedUrlAssembler.php
index 6d68c1e4bc20affae374141e86e8a0f1bdcda8f1..5e50f5e2b30617633100d69e24f1c5f11e2410de 100644 (file)
@@ -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,17 @@ class UnroutedUrlAssembler implements UnroutedUrlAssemblerInterface {
    */
   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']);
+
+    if ($parsed['fragment'] && !$options['fragment']) {
+      $options['fragment'] = '#' . $parsed['fragment'];
     }
 
     if (isset($options['https'])) {
@@ -88,7 +93,7 @@ class UnroutedUrlAssembler implements UnroutedUrlAssemblerInterface {
     }
     // Append the query.
     if ($options['query']) {
-      $uri .= (strpos($uri, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($options['query']);
+      $uri .= '?' . UrlHelper::buildQuery($options['query']);
     }
     // Reassemble.
     $url = $uri . $options['fragment'];