Permalink
Browse files

Allow escaping only attributes of a link and not it's title

  • Loading branch information...
1 parent 6fdbdf5 commit 75e7797a26ea02be33477cf7340048dabf759d7e @ADmad ADmad committed Jun 29, 2013
Showing with 28 additions and 2 deletions.
  1. +22 −0 lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
  2. +6 −2 lib/Cake/View/Helper/HtmlHelper.php
@@ -291,6 +291,17 @@ public function testLink() {
);
$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(
'controller' => 'images', 'action' => 'view', 3, '?' => array('height' => 100, 'width' => 200)
));
@@ -311,6 +322,17 @@ public function testLink() {
);
$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' => '#'));
$expected = array(
'a' => array('href' => '#'),
@@ -321,11 +321,12 @@ public function charset($charset = null) {
* ### Options
*
* - `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.
*
* @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 array $options Array of HTML attributes.
+ * @param array $options Array of options and HTML attributes.
* @param string $confirmMessage JavaScript confirmation message.
* @return string An `<a />` element.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::link
@@ -341,7 +342,10 @@ public function link($title, $url = null, $options = array(), $confirmMessage =
$escapeTitle = false;
}
- if (isset($options['escape'])) {
+ if (isset($options['escapeTitle'])) {
+ $escapeTitle = $options['escapeTitle'];
+ unset($options['escapeTitle']);
+ } elseif (isset($options['escape'])) {
$escapeTitle = $options['escape'];
}

0 comments on commit 75e7797

Please sign in to comment.