Fix double encoding in JsHelper request methods.

The urls were being HTML & URL encoded, this causes issues with URL's
containing query string parameters.  Remove HTML entities as they aren't
required in the Javascript context.

Fixes #3495
This commit is contained in:
mark_story 2013-01-02 23:09:37 -05:00
parent a949988208
commit 75f654b87b
4 changed files with 16 additions and 3 deletions

View file

@ -215,6 +215,18 @@ class JqueryEngineHelperTest extends CakeTestCase {
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }
/**
* Test that querystring arguments are not double escaped.
*
* @return void
*/
public function testRequestWithQueryStringArguments() {
$url = '/users/search/sort:User.name/direction:desc?nome=&cpm=&audience=public';
$result = $this->Jquery->request($url);
$expected = '$.ajax({url:"\\/users\\/search\\/sort:User.name\\/direction:desc?nome=&cpm=&audience=public"});';
$this->assertEquals($expected, $result);
}
/** /**
* test that alternate jQuery object values work for request() * test that alternate jQuery object values work for request()
* *

View file

@ -250,7 +250,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
* @see JsBaseEngineHelper::request() for options list. * @see JsBaseEngineHelper::request() for options list.
*/ */
public function request($url, $options = array()) { public function request($url, $options = array()) {
$url = $this->url($url); $url = html_entity_decode($this->url($url), ENT_COMPAT, Configure::read('App.encoding'));
$options = $this->_mapOptions('request', $options); $options = $this->_mapOptions('request', $options);
if (isset($options['data']) && is_array($options['data'])) { if (isset($options['data']) && is_array($options['data'])) {
$options['data'] = $this->_toQuerystring($options['data']); $options['data'] = $this->_toQuerystring($options['data']);

View file

@ -234,7 +234,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
* @return string The completed ajax call. * @return string The completed ajax call.
*/ */
public function request($url, $options = array()) { public function request($url, $options = array()) {
$url = $this->url($url); $url = html_entity_decode($this->url($url), ENT_COMPAT, Configure::read('App.encoding'));
$options = $this->_mapOptions('request', $options); $options = $this->_mapOptions('request', $options);
$type = $data = null; $type = $data = null;
if (isset($options['type']) || isset($options['update'])) { if (isset($options['type']) || isset($options['update'])) {

View file

@ -234,7 +234,8 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
* @return string The completed ajax call. * @return string The completed ajax call.
*/ */
public function request($url, $options = array()) { public function request($url, $options = array()) {
$url = '"' . $this->url($url) . '"'; $url = html_entity_decode($this->url($url), ENT_COMPAT, Configure::read('App.encoding'));
$url = '"' . $url . '"';
$options = $this->_mapOptions('request', $options); $options = $this->_mapOptions('request', $options);
$type = '.Request'; $type = '.Request';
if (isset($options['type']) && strtolower($options['type']) == 'json') { if (isset($options['type']) && strtolower($options['type']) == 'json') {