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
        );
    }