Skip to content
Permalink
Browse files

Url::parseQuery() accepts separator ;

  • Loading branch information...
dg committed Sep 30, 2019
1 parent f52ba7d commit 3f6d070b2eace41296521d37a7d38a3bc1f667d9
Showing with 34 additions and 1 deletion.
  1. +1 −1 src/Http/Url.php
  2. +31 −0 tests/Http/Url.parseQuery.semicolon.phpt
  3. +2 −0 tests/php-win.ini
@@ -429,7 +429,7 @@ function (array $m): string { return '%25' . strtoupper($m[1]); },
public static function parseQuery(string $s): array
{
$s = str_replace(['%5B', '%5b'], '[', $s);
$s = preg_replace('#&([^[&=]+)([^&]*)#', '&0[$1]$2', '&' . $s);
$s = preg_replace('#([&;])([^[&;=]+)([^&;]*)#', '&0[$2]$3', '&' . $s);
parse_str($s, $res);
return $res[0] ?? [];
}
@@ -0,0 +1,31 @@
<?php
/**
* Test: Nette\Http\Url::parseQuery()
*/
declare(strict_types=1);
use Nette\Http\Url;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
if (strpos(ini_get('arg_separator.input'), ';') === false) {
Tester\Environment::skip('arg_separator.input doesn\'t contain ;');
}
Assert::same([], Url::parseQuery(''));
Assert::same(['key' => ''], Url::parseQuery('key'));
Assert::same(['key' => ''], Url::parseQuery('key='));
Assert::same(['key' => 'val'], Url::parseQuery('key=val'));
Assert::same(['key' => ''], Url::parseQuery(';key=;'));
Assert::same(['a' => ['val', 'val']], Url::parseQuery('a[]=val;a[]=val'));
Assert::same(['a' => ['x' => 'val', 'y' => 'val']], Url::parseQuery('%61[x]=val;%61[y]=val'));
Assert::same(['a b' => 'val', 'c' => ['d e' => 'val']], Url::parseQuery('a b=val;c[d e]=val'));
Assert::same(['a.b' => 'val', 'c' => ['d.e' => 'val']], Url::parseQuery('a.b=val;c[d.e]=val'));
Assert::same(['key"\'' => '"\''], Url::parseQuery('key"\'="\'')); // magic quotes
Assert::same([], Url::parseQuery('%00')); // null
@@ -1,3 +1,5 @@
arg_separator.input = "&;"

[PHP]
extension_dir = "./ext"
extension=php_fileinfo.dll

0 comments on commit 3f6d070

Please sign in to comment.
You can’t perform that action at this time.