Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removing HtmlHelper::link()'s escapeTitle parameter. $options[escape]…

… now controls escaping of attributes and title text.
  • Loading branch information...
commit 6bb53a5c9df1d550ee50c4228487b822e99cd261 1 parent 7344c0c
@markstory markstory authored
View
34 cake/libs/view/helpers/html.php
@@ -300,15 +300,19 @@ function charset($charset = null) {
*
* If the $url is empty, $title is used instead.
*
+ * #### Options
+ *
+ * - `escape` Set to false to disable escaping of title and attributes.
+ *
* @param string $title The content to be wrapped by <a> tags.
* @param mixed $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
- * @param array $htmlAttributes Array of HTML attributes.
+ * @param array $options Array of HTML attributes.
* @param string $confirmMessage JavaScript confirmation message.
- * @param boolean $escapeTitle Whether or not $title should be HTML escaped.
* @return string An <a /> element.
* @access public
*/
- function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true) {
+ function link($title, $url = null, $options = array(), $confirmMessage = false) {
+ $escapeTitle = true;
if ($url !== null) {
$url = $this->url($url);
} else {
@@ -317,8 +321,8 @@ function link($title, $url = null, $htmlAttributes = array(), $confirmMessage =
$escapeTitle = false;
}
- if (isset($htmlAttributes['escape']) && $escapeTitle == true) {
- $escapeTitle = $htmlAttributes['escape'];
+ if (isset($options['escape'])) {
+ $escapeTitle = $options['escape'];
}
if ($escapeTitle === true) {
@@ -327,23 +331,23 @@ function link($title, $url = null, $htmlAttributes = array(), $confirmMessage =
$title = htmlentities($title, ENT_QUOTES, $escapeTitle);
}
- if (!empty($htmlAttributes['confirm'])) {
- $confirmMessage = $htmlAttributes['confirm'];
- unset($htmlAttributes['confirm']);
+ if (!empty($options['confirm'])) {
+ $confirmMessage = $options['confirm'];
+ unset($options['confirm']);
}
if ($confirmMessage) {
$confirmMessage = str_replace("'", "\'", $confirmMessage);
$confirmMessage = str_replace('"', '\"', $confirmMessage);
- $htmlAttributes['onclick'] = "return confirm('{$confirmMessage}');";
- } elseif (isset($htmlAttributes['default']) && $htmlAttributes['default'] == false) {
- if (isset($htmlAttributes['onclick'])) {
- $htmlAttributes['onclick'] .= ' event.returnValue = false; return false;';
+ $options['onclick'] = "return confirm('{$confirmMessage}');";
+ } elseif (isset($options['default']) && $options['default'] == false) {
+ if (isset($options['onclick'])) {
+ $options['onclick'] .= ' event.returnValue = false; return false;';
} else {
- $htmlAttributes['onclick'] = 'event.returnValue = false; return false;';
+ $options['onclick'] = 'event.returnValue = false; return false;';
}
- unset($htmlAttributes['default']);
+ unset($options['default']);
}
- return $this->output(sprintf($this->tags['link'], $url, $this->_parseAttributes($htmlAttributes), $title));
+ return $this->output(sprintf($this->tags['link'], $url, $this->_parseAttributes($options), $title));
}
/**
View
8 cake/tests/cases/libs/view/helpers/html.test.php
@@ -222,10 +222,10 @@ function testLink() {
$result = $this->Html->link('Next >', '#', array(
'title' => 'to escape &#8230; or not escape?',
'escape' => true
- ), false, false);
+ ));
$expected = array(
'a' => array('href' => '#', 'title' => 'to escape &amp;#8230; or not escape?'),
- 'Next >',
+ 'Next &gt;',
'/a'
);
$this->assertTags($result, $expected);
@@ -242,7 +242,7 @@ function testLink() {
Configure::write('Asset.timestamp', false);
- $result = $this->Html->link($this->Html->image('test.gif'), '#', array(), false, false, false);
+ $result = $this->Html->link($this->Html->image('test.gif'), '#', array('escape' => false));
$expected = array(
'a' => array('href' => '#'),
'img' => array('src' => 'img/test.gif', 'alt' => ''),
@@ -260,7 +260,7 @@ function testLink() {
Configure::write('Asset.timestamp', 'force');
- $result = $this->Html->link($this->Html->image('test.gif'), '#', array(), false, false, false);
+ $result = $this->Html->link($this->Html->image('test.gif'), '#', array('escape' => false));
$expected = array(
'a' => array('href' => '#'),
'img' => array('src' => 'preg:/img\/test\.gif\?\d*/', 'alt' => ''),
Please sign in to comment.
Something went wrong with that request. Please try again.