Skip to content

Commit

Permalink
Allow escaping only attributes of a link and not it's title
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jun 29, 2013
1 parent 6fdbdf5 commit 75e7797
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
22 changes: 22 additions & 0 deletions lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
Expand Up @@ -291,6 +291,17 @@ public function testLink() {
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);


$result = $this->Html->link('Next >', '#', array(
'title' => 'Next >',
'escapeTitle' => false
));
$expected = array(
'a' => array('href' => '#', 'title' => 'Next >'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);

$result = $this->Html->link('Original size', array( $result = $this->Html->link('Original size', array(
'controller' => 'images', 'action' => 'view', 3, '?' => array('height' => 100, 'width' => 200) 'controller' => 'images', 'action' => 'view', 3, '?' => array('height' => 100, 'width' => 200)
)); ));
Expand All @@ -311,6 +322,17 @@ public function testLink() {
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);


$result = $this->Html->link($this->Html->image('test.gif'), '#', array(
'title' => 'hey "howdy"',
'escapeTitle' => false
));
$expected = array(
'a' => array('href' => '#', 'title' => 'hey "howdy"'),
'img' => array('src' => 'img/test.gif', 'alt' => ''),
'/a'
);
$this->assertTags($result, $expected);

$result = $this->Html->image('test.gif', array('url' => '#')); $result = $this->Html->image('test.gif', array('url' => '#'));
$expected = array( $expected = array(
'a' => array('href' => '#'), 'a' => array('href' => '#'),
Expand Down
8 changes: 6 additions & 2 deletions lib/Cake/View/Helper/HtmlHelper.php
Expand Up @@ -321,11 +321,12 @@ public function charset($charset = null) {
* ### Options * ### Options
* *
* - `escape` Set to false to disable escaping of title and attributes. * - `escape` Set to false to disable escaping of title and attributes.
* - `escapeTitle` Set to false to disable escaping of title. (Takes precedence over value of `escape`)
* - `confirm` JavaScript confirmation message. * - `confirm` JavaScript confirmation message.
* *
* @param string $title The content to be wrapped by <a> tags. * @param string $title The content to be wrapped by <a> tags.
* @param string|array $url Cake-relative URL or array of URL parameters, or external URL (starts with http://) * @param string|array $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
* @param array $options Array of HTML attributes. * @param array $options Array of options and HTML attributes.
* @param string $confirmMessage JavaScript confirmation message. * @param string $confirmMessage JavaScript confirmation message.
* @return string An `<a />` element. * @return string An `<a />` element.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::link * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::link
Expand All @@ -341,7 +342,10 @@ public function link($title, $url = null, $options = array(), $confirmMessage =
$escapeTitle = false; $escapeTitle = false;
} }


if (isset($options['escape'])) { if (isset($options['escapeTitle'])) {
$escapeTitle = $options['escapeTitle'];
unset($options['escapeTitle']);
} elseif (isset($options['escape'])) {
$escapeTitle = $options['escape']; $escapeTitle = $options['escape'];
} }


Expand Down

0 comments on commit 75e7797

Please sign in to comment.