Browse Source

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
mark_story 13 years ago
parent
commit
75f654b87b

+ 12 - 0
lib/Cake/Test/Case/View/Helper/JqueryEngineHelperTest.php

@@ -216,6 +216,18 @@ class JqueryEngineHelperTest extends CakeTestCase {
 	}
 
 /**
+ * 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()
  *
  * @return void

+ 1 - 1
lib/Cake/View/Helper/JqueryEngineHelper.php

@@ -250,7 +250,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
  * @see JsBaseEngineHelper::request() for options list.
  */
 	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);
 		if (isset($options['data']) && is_array($options['data'])) {
 			$options['data'] = $this->_toQuerystring($options['data']);

+ 1 - 1
lib/Cake/View/Helper/MootoolsEngineHelper.php

@@ -234,7 +234,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
  * @return string The completed ajax call.
  */
 	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);
 		$type = $data = null;
 		if (isset($options['type']) || isset($options['update'])) {

+ 2 - 1
lib/Cake/View/Helper/PrototypeEngineHelper.php

@@ -234,7 +234,8 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
  * @return string The completed ajax call.
  */
 	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);
 		$type = '.Request';
 		if (isset($options['type']) && strtolower($options['type']) == 'json') {