mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing order inconsistency in queryString and bug with string based existing querystring
This commit is contained in:
parent
d73bc6b867
commit
e53074dab9
2 changed files with 46 additions and 2 deletions
|
@ -957,12 +957,19 @@ class Router {
|
||||||
$out = '';
|
$out = '';
|
||||||
|
|
||||||
if (is_array($q)) {
|
if (is_array($q)) {
|
||||||
$q = array_merge($extra, $q);
|
$q = array_merge($q, $extra);
|
||||||
} else {
|
} else {
|
||||||
$out = $q;
|
$out = $q;
|
||||||
$q = $extra;
|
$q = $extra;
|
||||||
}
|
}
|
||||||
$out .= http_build_query($q, null, $join);
|
$addition = http_build_query($q, null, $join);
|
||||||
|
|
||||||
|
if ($out && $addition) {
|
||||||
|
$out .= $join;
|
||||||
|
}
|
||||||
|
|
||||||
|
$out .= $addition;
|
||||||
|
|
||||||
if (isset($out[0]) && $out[0] != '?') {
|
if (isset($out[0]) && $out[0] != '?') {
|
||||||
$out = '?' . $out;
|
$out = '?' . $out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2590,4 +2590,41 @@ class RouterTest extends CakeTestCase {
|
||||||
Router::defaultRouteClass('NonExistentClass');
|
Router::defaultRouteClass('NonExistentClass');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests generating well-formed querystrings
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testQueryString() {
|
||||||
|
$result = Router::queryString(array('var' => 'foo bar'));
|
||||||
|
$expected = '?var=foo+bar';
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$result = Router::queryString(false, array('some' => 'param', 'foo' => 'bar'));
|
||||||
|
$expected = '?some=param&foo=bar';
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$existing = array('apple' => 'red', 'pear' => 'green');
|
||||||
|
$result = Router::queryString($existing, array('some' => 'param', 'foo' => 'bar'));
|
||||||
|
$expected = '?apple=red&pear=green&some=param&foo=bar';
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$existing = 'apple=red&pear=green';
|
||||||
|
$result = Router::queryString($existing, array('some' => 'param', 'foo' => 'bar'));
|
||||||
|
$expected = '?apple=red&pear=green&some=param&foo=bar';
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$existing = '?apple=red&pear=green';
|
||||||
|
$result = Router::queryString($existing, array('some' => 'param', 'foo' => 'bar'));
|
||||||
|
$expected = '?apple=red&pear=green&some=param&foo=bar';
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$result = Router::queryString('apple=red&pear=green');
|
||||||
|
$expected = '?apple=red&pear=green';
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$result = Router::queryString('foo=bar', array('php' => 'nut', 'jose' => 'zap'), true);
|
||||||
|
$expected = '?foo=bar&php=nut&jose=zap';
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue