diff --git a/core/lib/Drupal/Component/Utility/UrlHelper.php b/core/lib/Drupal/Component/Utility/UrlHelper.php index 1f5cc9145c5e4c7215be5324fc1a358cfdeaf668..70c59033d8025d40c7b18232c893041f271041a0 100644 --- a/core/lib/Drupal/Component/Utility/UrlHelper.php +++ b/core/lib/Drupal/Component/Utility/UrlHelper.php @@ -32,6 +32,9 @@ class UrlHelper { * @param string $parent * (optional) Internal use only. Used to build the $query array key for * nested items. Defaults to an empty string. + * @param string $is_external + * (optional) Determine if the processing query is part of external link + * and remove empty query parameters. * * @return string * A string encoded with rawurlencode() which can be used as or appended to @@ -39,7 +42,7 @@ class UrlHelper { * * @ingroup php_wrappers */ - public static function buildQuery(array $query, $parent = '') { + public static function buildQuery(array $query, $parent = '', $is_external = FALSE) { $params = []; foreach ($query as $key => $value) { @@ -50,7 +53,7 @@ public static function buildQuery(array $query, $parent = '') { $params[] = static::buildQuery($value, $key); } // If a query parameter value is NULL, only append its key. - elseif (!isset($value)) { + elseif (!isset($value)|| ($is_external && empty($value) && strlen($value) == 0)) { $params[] = $key; } else { diff --git a/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php b/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php index b4746186bf346060b516474b6617dd77169f05c8..faffd35d21754d5b7056bd09e546eb10a3a743b8 100644 --- a/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php +++ b/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php @@ -93,7 +93,7 @@ protected function buildExternalUrl($uri, array $options = [], $collect_bubbleab } // Append the query. if ($options['query']) { - $uri .= '?' . UrlHelper::buildQuery($options['query']); + $uri .= '?' . UrlHelper::buildQuery($options['query'], '', TRUE); } // Reassemble. $url = $uri . $options['fragment'];