diff --git a/core/includes/common.inc b/core/includes/common.inc
index 409fa67..2200637 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -228,7 +228,7 @@ function drupal_get_destination() {
   }
   else {
     $path = \Drupal::routeMatch()->getRouteName() ? Url::fromRouteMatch(\Drupal::routeMatch())->getInternalPath() : '';
-    $query = UrlHelper::buildQuery(UrlHelper::filterQueryParameters($query->all()));
+     $query = http_build_query(UrlHelper::filterQueryParameters($query->all()), NULL, NULL, PHP_QUERY_RFC3986);
     if ($query != '') {
       $path .= '?' . $query;
     }
diff --git a/core/includes/file.inc b/core/includes/file.inc
index effb71c..fd2bfd4 100644
--- a/core/includes/file.inc
+++ b/core/includes/file.inc
@@ -326,7 +326,7 @@ function file_create_url($uri) {
       $path = $GLOBALS['base_url'] . '/' . UrlHelper::encodePath($options['path']);
       // Append the query.
       if ($options['query']) {
-        $path .= '?' . UrlHelper::buildQuery($options['query']);
+        $path .= '?' . http_build_query($options['query'], NULL, NULL, PHP_QUERY_RFC3986);
       }
 
       // Append fragment.
diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index 1ec434d..c87dd8b 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -888,7 +888,7 @@ function install_get_form($form_id, array &$install_state) {
  * @see install_full_redirect_url()
  */
 function install_redirect_url($install_state) {
-  return 'core/install.php?' . UrlHelper::buildQuery($install_state['parameters']);
+  return 'core/install.php?' . http_build_query($install_state['parameters'], NULL, NULL, PHP_QUERY_RFC3986);
 }
 
 /**
diff --git a/core/includes/install.inc b/core/includes/install.inc
index ad911db..029392b 100644
--- a/core/includes/install.inc
+++ b/core/includes/install.inc
@@ -872,7 +872,7 @@ function drupal_current_script_url($query = array()) {
   $uri = $_SERVER['SCRIPT_NAME'];
   $query = array_merge(UrlHelper::filterQueryParameters(\Drupal::request()->query->all()), $query);
   if (!empty($query)) {
-    $uri .= '?' . UrlHelper::buildQuery($query);
+    $uri .= '?' . http_build_query($query, NULL, NULL, PHP_QUERY_RFC3986);
   }
   return $uri;
 }
diff --git a/core/lib/Drupal/Component/Utility/UrlHelper.php b/core/lib/Drupal/Component/Utility/UrlHelper.php
index 691413e..30490a3 100644
--- a/core/lib/Drupal/Component/Utility/UrlHelper.php
+++ b/core/lib/Drupal/Component/Utility/UrlHelper.php
@@ -22,55 +22,6 @@ class UrlHelper {
   protected static $allowedProtocols = array('http', 'https');
 
   /**
-   * Parses an array into a valid, rawurlencoded query string.
-   *
-   *
-   * rawurlencode() is RFC3986 compliant, and as a consequence RFC3987
-   * compliant. The latter defines the required format of "URLs" in HTML5.
-   * urlencode() is almost the same as rawurlencode(), except that it encodes
-   * spaces as "+" instead of "%20". This makes its result non compliant to
-   * RFC3986 and as a consequence non compliant to RFC3987 and as a consequence
-   * not valid as a "URL" in HTML5.
-   *
-   * @todo Remove this function once PHP 5.4 is required as we can use just
-   *   http_build_query() directly.
-   *
-   * @param array $query
-   *   The query parameter array to be processed,
-   *   e.g. \Drupal::request()->query->all().
-   * @param string $parent
-   *   Internal use only. Used to build the $query array key for nested items.
-   *
-   * @return string
-   *   A rawurlencoded string which can be used as or appended to the URL query
-   *   string.
-   *
-   * @ingroup php_wrappers
-   */
-  public static function buildQuery(array $query, $parent = '') {
-    $params = array();
-
-    foreach ($query as $key => $value) {
-      $key = ($parent ? $parent . '[' . rawurlencode($key) . ']' : rawurlencode($key));
-
-      // Recurse into children.
-      if (is_array($value)) {
-        $params[] = static::buildQuery($value, $key);
-      }
-      // If a query parameter value is NULL, only append its key.
-      elseif (!isset($value)) {
-        $params[] = $key;
-      }
-      else {
-        // For better readability of paths in query strings, we decode slashes.
-        $params[] = $key . '=' . str_replace('%2F', '/', rawurlencode($value));
-      }
-    }
-
-    return implode('&', $params);
-  }
-
-  /**
    * Filters a URL query parameter array to remove unwanted elements.
    *
    * @param array $query
diff --git a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php
index b8393b2..84b13ad 100644
--- a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php
+++ b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php
@@ -353,7 +353,7 @@ protected function preSave(array &$link, array $original) {
     asort($fields['route_parameters']);
     // Since this will be urlencoded, it's safe to store and match against a
     // text field.
-    $fields['route_param_key'] = $fields['route_parameters'] ? UrlHelper::buildQuery($fields['route_parameters']) : '';
+    $fields['route_param_key'] = $fields['route_parameters'] ? http_build_query($fields['route_parameters'], NULL, NULL, PHP_QUERY_RFC3986) : '';
 
     foreach ($this->serializedFields() as $name) {
       $fields[$name] = serialize($fields[$name]);
@@ -647,7 +647,7 @@ public function loadByRoute($route_name, array $route_parameters = array(), $men
     // text field.
     // @todo Standardize an efficient way to load by route name and parameters
     //   in place of system path. https://www.drupal.org/node/2302139
-    $param_key = $route_parameters ? UrlHelper::buildQuery($route_parameters) : '';
+    $param_key = $route_parameters ? http_build_query(UrlHelper::filterQueryParameters($route_parameters, NULL, NULL, PHP_QUERY_RFC3986)) : '';
     $query = $this->connection->select($this->table, $this->options);
     $query->fields($this->table, $this->definitionFields());
     $query->condition('route_name', $route_name);
diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php
index b964e6d..166f39d 100644
--- a/core/lib/Drupal/Core/Routing/UrlGenerator.php
+++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
@@ -271,8 +271,8 @@ public function generateFromPath($path = NULL, $options = array()) {
         }
       }
       // Append the query.
-      if ($options['query']) {
-        $path .= (strpos($path, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($options['query']);
+      if ($options['query']) {$path .= (strpos($path, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($options['query']);
+        $path .= (strpos($path, '?') !== FALSE ? '&' : '?') . http_build_query($options['query'], NULL, NULL, PHP_QUERY_RFC3986);
       }
       if (isset($options['https'])) {
         if ($options['https'] === TRUE) {
@@ -315,8 +315,8 @@ public function generateFromPath($path = NULL, $options = array()) {
     $prefix = empty($path) ? rtrim($options['prefix'], '/') : $options['prefix'];
 
     $path = str_replace('%2F', '/', rawurlencode($prefix . $path));
-    $query = $options['query'] ? ('?' . UrlHelper::buildQuery($options['query'])) : '';
-    return $base . $options['script'] . $path . $query . $options['fragment'];
+    $query = $options['query'] ? ('?' . http_build_query($options['query'], NULL, NULL, PHP_QUERY_RFC3986)) : '';
+    return $base . $options['script'] . $path . $query . $options['fragment'];$query = $options['query'] ? ('?' . UrlHelper::buildQuery($options['query'])) : '';
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php b/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php
index c0ce73b..89b0b79 100644
--- a/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php
+++ b/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php
@@ -95,7 +95,7 @@ protected function buildExternalUrl($uri, array $options = []) {
     }
     // Append the query.
     if ($options['query']) {
-      $uri .= (strpos($uri, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($options['query']);
+      $uri .= (strpos($uri, '?') !== FALSE ? '&' : '?') . http_build_query($options['query'], NULL, NULL, PHP_QUERY_RFC3986);
     }
     // Reassemble.
     return $uri . $options['fragment'];
@@ -144,7 +144,7 @@ protected function buildLocalUrl($uri, array $options = []) {
     $prefix = empty($uri) ? rtrim($options['prefix'], '/') : $options['prefix'];
 
     $uri = str_replace('%2F', '/', rawurlencode($prefix . $uri));
-    $query = $options['query'] ? ('?' . UrlHelper::buildQuery($options['query'])) : '';
+    $query = $options['query'] ? ('?' . http_build_query($options['query'], NULL, NULL, PHP_QUERY_RFC3986)) : '';
     return $base . $options['script'] . $uri . $query . $options['fragment'];
   }
 
diff --git a/core/modules/contextual/contextual.module b/core/modules/contextual/contextual.module
index b7e8ef2..832f54a 100644
--- a/core/modules/contextual/contextual.module
+++ b/core/modules/contextual/contextual.module
@@ -154,13 +154,13 @@ function contextual_contextual_links_view_alter(&$element, $items) {
  *   use in a data- attribute.
  */
 function _contextual_links_to_id($contextual_links) {
-  $ids = array();
-  foreach ($contextual_links as $group => $args) {
-    $route_parameters = UrlHelper::buildQuery($args['route_parameters']);
-    $metadata = UrlHelper::buildQuery((isset($args['metadata'])) ? $args['metadata'] : array());
-    $ids[] = "{$group}:{$route_parameters}:{$metadata}";
-  }
-  return implode('|', $ids);
+    $ids = array();
+    foreach ($contextual_links as $group => $args) {
+        $route_parameters = http_build_query($args['route_parameters'], NULL, NULL, PHP_QUERY_RFC3986);
+        $metadata = http_build_query((isset($args['metadata'])) ? $args['metadata'] : array(), NULL, NULL, PHP_QUERY_RFC3986);
+        $ids[] = "{$group}:{$route_parameters}:{$metadata}";
+    }
+    return implode('|', $ids);
 }
 
 /**
diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php
index a87554c..53252b4 100644
--- a/core/modules/image/src/Entity/ImageStyle.php
+++ b/core/modules/image/src/Entity/ImageStyle.php
@@ -228,7 +228,7 @@ public function buildUrl($path, $clean_urls = NULL) {
     $file_url = file_create_url($uri);
     // Append the query string with the token, if necessary.
     if ($token_query) {
-      $file_url .= (strpos($file_url, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($token_query);
+      $file_url .= (strpos($file_url, '?') !== FALSE ? '&' : '?') . http_build_query($token_query, NULL, NULL, PHP_QUERY_RFC3986);
     }
 
     return $file_url;
diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php
index 0882384..8555955 100644
--- a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php
+++ b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php
@@ -241,7 +241,7 @@ public function form(array $form, FormStateInterface $form_state) {
     // fragment. https://www.drupal.org/node/2305013
     $options = $url->getOptions();
     if (isset($options['query'])) {
-      $default_value .= $options['query'] ? ('?' . UrlHelper::buildQuery($options['query'])) : '';
+      $default_value .= $options['query'] ? ('?' . http_build_query($options['query'], NULL, NULL, PHP_QUERY_RFC3986)) : '';
     }
     if (isset($options['fragment']) && $options['fragment'] !== '') {
       $default_value .= '#' . $options['fragment'];
diff --git a/core/modules/system/src/Tests/Common/UrlTest.php b/core/modules/system/src/Tests/Common/UrlTest.php
index 92342d2..24baada 100644
--- a/core/modules/system/src/Tests/Common/UrlTest.php
+++ b/core/modules/system/src/Tests/Common/UrlTest.php
@@ -15,8 +15,7 @@
 /**
  * Confirm that _url(),
  * \Drupal\Component\Utility\UrlHelper::filterQueryParameters(),
- * \Drupal\Component\Utility\UrlHelper::buildQuery(), and _l() work correctly
- * with various input.
+ * http_build_query, and _l() work correctly with various input.
  *
  * _url() calls \Drupal::moduleHandler()->getImplementations(),
  * which may issue a db query, which requires
diff --git a/core/modules/views/src/Controller/ViewAjaxController.php b/core/modules/views/src/Controller/ViewAjaxController.php
index 401b0f9..fc35485 100644
--- a/core/modules/views/src/Controller/ViewAjaxController.php
+++ b/core/modules/views/src/Controller/ViewAjaxController.php
@@ -122,7 +122,7 @@ public function ajaxView(Request $request) {
         // Overwrite the destination.
         // @see drupal_get_destination()
         $origin_destination = $path;
-        $query = UrlHelper::buildQuery($request->query->all());
+         $query = http_build_query($request->query->all(), NULL, NULL, PHP_QUERY_RFC3986);
         if ($query != '') {
           $origin_destination .= '?' . $query;
         }
diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php
index 6066d9d..1699d95 100644
--- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php
+++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php
@@ -1360,7 +1360,7 @@ protected function renderAsLink($alter, $text, $tokens) {
         }
         // Replace any empty query params from URL parsing with NULL. So the
         // query will get built correctly with only the param key.
-        // @see \Drupal\Component\Utility\UrlHelper::buildQuery().
+        // @see http_build_query().
         if ($val === '') {
           $url['query'][$param] = NULL;
         }
@@ -1413,7 +1413,7 @@ protected function renderAsLink($alter, $text, $tokens) {
     if (isset($alter['query'])) {
       // Convert the query to a string, perform token replacement, and then
       // convert back to an array form for _l().
-      $options['query'] = UrlHelper::buildQuery($alter['query']);
+      $options['query'] = http_build_query($alter['query'], NULL, NULL, PHP_QUERY_RFC3986);
       $options['query'] = $this->viewsTokenReplace($options['query'], $tokens);
       $query = array();
       parse_str($options['query'], $query);
diff --git a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php
index 0477b7a..93af89f 100644
--- a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php
@@ -37,7 +37,6 @@ public function providerTestBuildQuery() {
    * Tests query building.
    *
    * @dataProvider providerTestBuildQuery
-   * @covers ::buildQuery
    *
    * @param array $query
    *   The array of query parameters.
@@ -47,7 +46,7 @@ public function providerTestBuildQuery() {
    *   The assertion message.
    */
   public function testBuildQuery($query, $expected, $message) {
-    $this->assertEquals(UrlHelper::buildQuery($query), $expected, $message);
+    $this->assertEquals(http_build_query($query, NULL, NULL, PHP_QUERY_RFC3986), $expected, $message);
   }
 
   /**
diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php
index 1de4249..3d9e879 100644
--- a/core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php
+++ b/core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php
@@ -113,7 +113,7 @@ public function testHandleWithPostRequest() {
     $this->customPageSubscriber->onException($event);
 
     $response = $event->getResponse();
-    $result = $response->getContent() . " " . UrlHelper::buildQuery($request->request->all());
+    $result = $response->getContent() . " " . http_build_query($request->request->all(), NULL, NULL, PHP_QUERY_RFC3986); 
     $this->assertEquals('POST name=druplicon&pass=12345', $result);
   }
 
@@ -127,14 +127,14 @@ public function testHandleWithGetRequest() {
     $request->attributes->set('_system_path', 'test');
 
     $this->kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
-      return new Response($request->getMethod() . ' ' . UrlHelper::buildQuery($request->query->all()));
+      return new Response($request->getMethod() . ' ' . http_build_query($request->query->all(), NULL, NULL, PHP_QUERY_RFC3986));
     }));
 
     $event = new GetResponseForExceptionEvent($this->kernel, $request, 'foo', new NotFoundHttpException('foo'));
     $this->customPageSubscriber->onException($event);
 
     $response = $event->getResponse();
-    $result = $response->getContent() . " " . UrlHelper::buildQuery($request->request->all());
+    $result = $response->getContent() . " " . http_build_query($request->request->all(), NULL, NULL, PHP_QUERY_RFC3986);
     $this->assertEquals('GET name=druplicon&pass=12345&destination=test&_exception_statuscode=404 ', $result);
   }
 
