Skip to content
Permalink
Browse files

Fixing order inconsistency in queryString and bug with string based e…

…xisting querystring
  • Loading branch information...
Jelle Henkens
Jelle Henkens committed May 7, 2012
1 parent a1e06b9 commit 45a96ae588f88ea1046b327a12a564fb094903fc
Showing with 46 additions and 2 deletions.
  1. +9 −2 lib/Cake/Routing/Router.php
  2. +37 −0 lib/Cake/Test/Case/Routing/RouterTest.php
@@ -957,12 +957,19 @@ public static function queryString($q, $extra = array(), $escape = false) {
$out = '';
if (is_array($q)) {
$q = array_merge($extra, $q);
$q = array_merge($q, $extra);
} else {
$out = $q;
$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] != '?') {
$out = '?' . $out;
}
@@ -2590,4 +2590,41 @@ public function testSettingNonExistentDefaultRouteException() {
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);
}
}

0 comments on commit 45a96ae

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.