Skip to content

Commit b53e49a

Browse files
[HttpFoundation] add HeaderUtils::parseQuery(): it does the same as parse_str() but preserves dots in variable names
1 parent aa59a52 commit b53e49a

File tree

2 files changed

+3
-47
lines changed

2 files changed

+3
-47
lines changed

Controller/RedirectController.php

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Controller;
1313

14+
use Symfony\Component\HttpFoundation\HeaderUtils;
1415
use Symfony\Component\HttpFoundation\RedirectResponse;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\HttpFoundation\Response;
@@ -65,7 +66,7 @@ public function redirectAction(Request $request, string $route, bool $permanent
6566

6667
if ($keepQueryParams) {
6768
if ($query = $request->server->get('QUERY_STRING')) {
68-
$query = self::parseQuery($query);
69+
$query = HeaderUtils::parseQuery($query);
6970
} else {
7071
$query = $request->query->all();
7172
}
@@ -185,49 +186,4 @@ public function __invoke(Request $request): Response
185186

186187
throw new \RuntimeException(sprintf('The parameter "path" or "route" is required to configure the redirect action in "%s" routing configuration.', $request->attributes->get('_route')));
187188
}
188-
189-
private static function parseQuery(string $query)
190-
{
191-
$q = [];
192-
193-
foreach (explode('&', $query) as $v) {
194-
if (false !== $i = strpos($v, "\0")) {
195-
$v = substr($v, 0, $i);
196-
}
197-
198-
if (false === $i = strpos($v, '=')) {
199-
$k = urldecode($v);
200-
$v = '';
201-
} else {
202-
$k = urldecode(substr($v, 0, $i));
203-
$v = substr($v, $i);
204-
}
205-
206-
if (false !== $i = strpos($k, "\0")) {
207-
$k = substr($k, 0, $i);
208-
}
209-
210-
$k = ltrim($k, ' ');
211-
212-
if (false === $i = strpos($k, '[')) {
213-
$q[] = bin2hex($k).$v;
214-
} else {
215-
$q[] = substr_replace($k, bin2hex(substr($k, 0, $i)), 0, $i).$v;
216-
}
217-
}
218-
219-
parse_str(implode('&', $q), $q);
220-
221-
$query = [];
222-
223-
foreach ($q as $k => $v) {
224-
if (false !== $i = strpos($k, '_')) {
225-
$query[substr_replace($k, hex2bin(substr($k, 0, $i)).'[', 0, 1 + $i)] = $v;
226-
} else {
227-
$query[hex2bin($k)] = $v;
228-
}
229-
}
230-
231-
return $query;
232-
}
233189
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"symfony/dependency-injection": "^5.2",
2424
"symfony/event-dispatcher": "^5.1",
2525
"symfony/error-handler": "^4.4.1|^5.0.1",
26-
"symfony/http-foundation": "^4.4|^5.0",
26+
"symfony/http-foundation": "^5.2",
2727
"symfony/http-kernel": "^5.2",
2828
"symfony/polyfill-mbstring": "~1.0",
2929
"symfony/polyfill-php80": "^1.15",

0 commit comments

Comments
 (0)