mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Updating Router::queryString() and Router::url() to allow additional parameters to force escaping of & used in query strings. Tests added. Refs #5982
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7987 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
ba42eb05c1
commit
7c87d36d74
2 changed files with 24 additions and 6 deletions
|
@ -740,7 +740,10 @@ class Router extends Object {
|
|||
* or an array specifying any of the following: 'controller', 'action',
|
||||
* and/or 'plugin', in addition to named arguments (keyed array elements),
|
||||
* and standard URL arguments (indexed array elements)
|
||||
* @param boolean $full If true, the full base URL will be prepended to the result
|
||||
* @param mixed $options If (bool)true, the full base URL will be prepended to the result.
|
||||
* If an array accepts the following keys
|
||||
* escape - used when making urls embedded in html escapes query string '&'
|
||||
* full - if true the full base URL will be prepended.
|
||||
* @return string Full translated URL with base path.
|
||||
* @access public
|
||||
* @static
|
||||
|
@ -749,6 +752,12 @@ class Router extends Object {
|
|||
$_this =& Router::getInstance();
|
||||
$defaults = $params = array('plugin' => null, 'controller' => null, 'action' => 'index');
|
||||
|
||||
if (is_bool($full)) {
|
||||
$escape = false;
|
||||
} else {
|
||||
extract(array_merge(array('escape' => false, 'full' => false), $full));
|
||||
}
|
||||
|
||||
if (!empty($_this->__params)) {
|
||||
if (isset($this) && !isset($this->params['requested'])) {
|
||||
$params = $_this->__params[0];
|
||||
|
@ -919,7 +928,7 @@ class Router extends Object {
|
|||
$output = substr($output, 0, -1);
|
||||
}
|
||||
|
||||
return $output . $extension . $_this->queryString($q) . $frag;
|
||||
return $output . $extension . $_this->queryString($q, array(), $escape) . $frag;
|
||||
}
|
||||
/**
|
||||
* Maps a URL array onto a route and returns the string result, or false if no match
|
||||
|
@ -1140,15 +1149,20 @@ class Router extends Object {
|
|||
* Generates a well-formed querystring from $q
|
||||
*
|
||||
* @param mixed $q Query string
|
||||
* @param array $extra Extra querystring parameters
|
||||
* @param array $extra Extra querystring parameters.
|
||||
* @param bool $escape Whether or not to use escaped &
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function queryString($q, $extra = array()) {
|
||||
function queryString($q, $extra = array(), $escape = false) {
|
||||
if (empty($q) && empty($extra)) {
|
||||
return null;
|
||||
}
|
||||
$join = '&';
|
||||
if ($escape === true) {
|
||||
$join = '&';
|
||||
}
|
||||
$out = '';
|
||||
|
||||
if (is_array($q)) {
|
||||
|
@ -1157,7 +1171,7 @@ class Router extends Object {
|
|||
$out = $q;
|
||||
$q = $extra;
|
||||
}
|
||||
$out .= http_build_query($q, null, '&');
|
||||
$out .= http_build_query($q, null, $join);
|
||||
if (isset($out[0]) && $out[0] != '?') {
|
||||
$out = '?' . $out;
|
||||
}
|
||||
|
|
|
@ -1059,6 +1059,10 @@ class RouterTest extends CakeTestCase {
|
|||
$result = Router::url(array('controller' => 'posts', 'action'=>'index', '0', '?' => array('var' => 'test', 'var2' => 'test2', 'more' => 'test data')));
|
||||
$this->assertEqual($result, $expected);
|
||||
ini_set('arg_separator.output', $restore);
|
||||
|
||||
$result = Router::url(array('controller' => 'posts', 'action'=>'index', '0', '?' => array('var' => 'test', 'var2' => 'test2')), array('escape' => true));
|
||||
$expected = '/posts/index/0?var=test&var2=test2';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testConnectNamed method
|
||||
|
|
Loading…
Add table
Reference in a new issue