function UrlHelper::compressQueryParameter

Same name in other branches
  1. 10 core/lib/Drupal/Component/Utility/UrlHelper.php \Drupal\Component\Utility\UrlHelper::compressQueryParameter()

Compresses a string for use in a query parameter.

While RFC 1738 doesn't specify a maximum length for query strings, browsers or server configurations may restrict URLs and/or query strings to a certain length, often 1000 or 2000 characters. This method can be used to compress a string into a URL-safe query parameter which will be shorter than if it was used directly.

Parameters

string $data: The data to compress.

Return value

string The data compressed into a URL-safe string.

See also

\Drupal\Component\Utility\UrlHelper::uncompressQueryParameter()

9 calls to UrlHelper::compressQueryParameter()
AjaxPageStateTest::testDrupalSettingsIsNotLoaded in core/modules/system/tests/src/Functional/Render/AjaxPageStateTest.php
Give ajax_page_state[libraries]=core/drupalSettings to exclude the library.
AjaxPageStateTest::testMultipleLibrariesAreNotLoaded in core/modules/system/tests/src/Functional/Render/AjaxPageStateTest.php
Tests if multiple libraries can be excluded.
AjaxTest::testDrupalSettingsCachingRegression in core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php
Tests that AJAX loaded libraries are not retained between requests.
AssetOptimizationTest::setInvalidLibrary in core/tests/Drupal/FunctionalTests/Asset/AssetOptimizationTest.php
Replaces the 'include' entry in the given URL with an invalid value.
AssetResolver::getJsAssets in core/lib/Drupal/Core/Asset/AssetResolver.php
Returns the JavaScript assets for the current response's libraries.

... See full list

File

core/lib/Drupal/Component/Utility/UrlHelper.php, line 82

Class

UrlHelper
Helper class URL based methods.

Namespace

Drupal\Component\Utility

Code

public static function compressQueryParameter(string $data) : string {
    // Use 'base64url' encoding. Note that the '=' sign is only used for padding
    // on the right of the string, and is otherwise not part of the data.
    // @see https://datatracker.ietf.org/doc/html/rfc4648#section-5
    // @see https://www.php.net/manual/en/function.base64-encode.php#123098
    return str_replace([
        '+',
        '/',
        '=',
    ], [
        '-',
        '_',
        '',
    ], base64_encode(gzcompress($data)));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.