Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
QueryStringParser
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 correctServerQueryString
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 encodeXpression
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Symftony\Xpression;
6
7class QueryStringParser
8{
9    public static function correctServerQueryString(): void
10    {
11        if (isset($_SERVER['QUERY_STRING'])) {
12            $_SERVER['QUERY_STRING'] = self::encodeXpression($_SERVER['QUERY_STRING']);
13            parse_str($_SERVER['QUERY_STRING'], $_GET);
14        }
15    }
16
17    /**
18     * @return string
19     */
20    public static function encodeXpression(string $queryString)
21    {
22        return preg_replace_callback(
23            '/(=)\{([^}]*(?:}}[^}]*)*)(?:(?:}(&))|(?:}$))/',
24            static fn ($matches) => $matches[1].urlencode($matches[2]).($matches[3] ?? ''),
25            urldecode($queryString)
26        );
27    }
28}