diff --git a/core/lib/Drupal/Component/Utility/UrlHelper.php b/core/lib/Drupal/Component/Utility/UrlHelper.php
index c286db9..23ece0c 100644
--- a/core/lib/Drupal/Component/Utility/UrlHelper.php
+++ b/core/lib/Drupal/Component/Utility/UrlHelper.php
@@ -51,7 +51,7 @@ public static function buildQuery(array $query, $parent = '') {
     $params = array();
 
     foreach ($query as $key => $value) {
-      $key = ($parent ? $parent . '[' . rawurlencode($key) . ']' : rawurlencode($key));
+      $key = ($parent ? : '') . rawurlencode($parent ? '[' . $key . ']' : $key);
 
       // Recurse into children.
       if (is_array($value)) {
