diff --git a/core/lib/Drupal/Component/Utility/HttpQuery.php b/core/lib/Drupal/Component/Utility/HttpQuery.php index c4050c0..cbdb33b 100644 --- a/core/lib/Drupal/Component/Utility/HttpQuery.php +++ b/core/lib/Drupal/Component/Utility/HttpQuery.php @@ -12,8 +12,18 @@ class HttpQuery { /** * Parses an array into a valid, rawurlencoded query string. * - * This differs from http_build_query() as we need to rawurlencode() (instead of - * urlencode()) all query parameters. + * This function does the same as http_build_query() but it is using + * rawurlencode instead of urlencode. + * + * 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. $_GET. @@ -28,6 +38,11 @@ class HttpQuery { * @ingroup php_wrappers */ public static function buildQuery(array $query, $parent = '') { + // Use the php method for it, on PHP 5.4 and newer. + if (version_compare(PHP_VERSION, '5.4.0') < 0) { + return http_build_query($query, NULL, NULL, PHP_QUERY_RFC3986); + } + $params = array(); foreach ($query as $key => $value) {