Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixing entity encoding of url strings inside remoteFunctions containe…
…d in safe CDATA blocks. Fixes #127
  • Loading branch information
markstory committed Feb 9, 2010
1 parent 2cf294a commit 0fda18d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cake/libs/view/helpers/ajax.php
Expand Up @@ -212,6 +212,7 @@ function link($title, $href = null, $options = array(), $confirm = null, $escape
unset($confirm);
}
$htmlOptions = $this->__getHtmlOptions($options, array('url'));
$options += array('safe' => true);

if (empty($options['fallback']) || !isset($options['fallback'])) {
$options['fallback'] = $href;
Expand Down Expand Up @@ -257,7 +258,14 @@ function remoteFunction($options) {
$func = "new Ajax.Request(";
}

$func .= "'" . $this->url(isset($options['url']) ? $options['url'] : "") . "'";
$url = isset($options['url']) ? $options['url'] : "";
if (empty($options['safe'])) {
$url = $this->url($url);
} else {
$url = Router::url($url);
}

$func .= "'" . $url . "'";
$func .= ", " . $this->__optionsForAjax($options) . ")";

if (isset($options['before'])) {
Expand Down
7 changes: 7 additions & 0 deletions cake/tests/cases/libs/view/helpers/ajax.test.php
Expand Up @@ -557,6 +557,13 @@ function testLink() {
$this->assertPattern("/Event.observe\('link[0-9]+', [\w\d,'\(\)\s{}]+Ajax\.Request\([\w\d\s,'\(\){}:\/]+onComplete:function\(request, json\) {test}/", $result);
$this->assertNoPattern('/^<a[^<>]+complete="test"[^<>]*>Ajax Link<\/a>/', $result);
$this->assertNoPattern('/^<a\s+[^<>]*url="[^"]*"[^<>]*>/', $result);

$result = $this->Ajax->link(
'Ajax Link',
array('controller' => 'posts', 'action' => 'index', '?' => array('one' => '1', 'two' => '2')),
array('update' => 'myDiv', 'id' => 'myLink')
);
$this->assertPattern('#/posts/\?one\=1\&two\=2#', $result);
}
/**
* testRemoteTimer method
Expand Down

0 comments on commit 0fda18d

Please sign in to comment.