Permalink
Browse files

Fix missing HTML encoding on URL's generated by Html->meta().

The input URL was not correctly handled as an asset URL and thus was
not correctly HTML or URL escaped. This created invalid HTML when
favicon URLs included query string arguments.

Refs #2233
  • Loading branch information...
1 parent bf2f2e7 commit 8d38861a2e0db0db9ec732f9f6c536999ce3b3ce @markstory markstory committed Nov 9, 2013
Showing with 36 additions and 11 deletions.
  1. +35 −9 lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
  2. +1 −2 lib/Cake/View/Helper/HtmlHelper.php
@@ -1711,28 +1711,54 @@ public function testMeta() {
);
$this->assertTags($result, $expected);
+ $result = $this->Html->meta('keywords', 'these, are, some, meta, keywords');
+ $this->assertTags($result, array('meta' => array('name' => 'keywords', 'content' => 'these, are, some, meta, keywords')));
+ $this->assertRegExp('/\s+\/>$/', $result);
+
+ $result = $this->Html->meta('description', 'this is the meta description');
+ $this->assertTags($result, array('meta' => array('name' => 'description', 'content' => 'this is the meta description')));
+
+ $result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'));
+ $this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
+ }
+
+/**
+ * Test generating favicon's with meta()
+ *
+ * @return void
+ */
+ public function testMetaIcon() {
$result = $this->Html->meta('icon', 'favicon.ico');
$expected = array(
'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
);
$this->assertTags($result, $expected);
+
$result = $this->Html->meta('icon');
$expected = array(
'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
);
$this->assertTags($result, $expected);
- $result = $this->Html->meta('keywords', 'these, are, some, meta, keywords');
- $this->assertTags($result, array('meta' => array('name' => 'keywords', 'content' => 'these, are, some, meta, keywords')));
- $this->assertRegExp('/\s+\/>$/', $result);
-
- $result = $this->Html->meta('description', 'this is the meta description');
- $this->assertTags($result, array('meta' => array('name' => 'description', 'content' => 'this is the meta description')));
-
- $result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'));
- $this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
+ $result = $this->Html->meta('icon', '/favicon.png?one=two&three=four');
+ $url = '/favicon.png?one=two&three=four';
+ $expected = array(
+ 'link' => array(
+ 'href' => $url,
+ 'type' => 'image/x-icon',
+ 'rel' => 'icon'
+ ),
+ array(
+ 'link' => array(
+ 'href' => $url,
+ 'type' => 'image/x-icon',
+ 'rel' => 'shortcut icon'
+ )
+ )
+ );
+ $this->assertTags($result, $expected);
}
/**
@@ -276,11 +276,10 @@ public function meta($type, $url = null, $options = array()) {
$out = null;
if (isset($options['link'])) {
+ $options['link'] = $this->assetUrl($options['link']);
if (isset($options['rel']) && $options['rel'] === 'icon') {
$out = sprintf($this->_tags['metalink'], $options['link'], $this->_parseAttributes($options, array('block', 'link'), ' ', ' '));
$options['rel'] = 'shortcut icon';
- } else {
- $options['link'] = $this->url($options['link'], true);
}
$out .= sprintf($this->_tags['metalink'], $options['link'], $this->_parseAttributes($options, array('block', 'link'), ' ', ' '));
} else {

0 comments on commit 8d38861

Please sign in to comment.