src/Uri.php
private static function filterQueryString(?string $queryString): ?string
    {
        if ($queryString === null) {
            return null;
        }

        /** @link https://tools.ietf.org/html/rfc3986#section-3.4 */
        return preg_replace_callback(
            '/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/',
            function ($match) {
                return rawurlencode($match[0]);
            },
            $queryString
        );
    }
private static function filterQueryString(?string $queryString): ?string
    {
        if ($queryString === null) {
            return null;
        }

        /** @link https://tools.ietf.org/html/rfc3986#section-3.4 */
        return preg_replace_callback(
            '/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/',
            function ($match) {
                return rawurlencode($match[0]);
            },
            $queryString
        );
    }
Filters the URI query string and percent-encodes reserved characters

@param string|null $queryString The query string to filter if one is set, otherwise null
@return string|null The filtered query string, or null if the query string was already null