BUG Fix encoding of SiteTree.MetaTags

This commit is contained in:
Damian Mooyman 2014-04-29 08:54:17 +12:00
parent 9bff36c078
commit 89fbae2c2e
3 changed files with 118 additions and 92 deletions

View File

@ -1380,7 +1380,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
public function MetaTags($includeTitle = true) {
$tags = "";
if($includeTitle === true || $includeTitle == 'true') {
$tags .= "<title>" . $this->Title . "</title>\n";
$tags .= "<title>" . Convert::raw2xml($this->Title) . "</title>\n";
}
$generator = trim(Config::inst()->get('SiteTree', 'meta_generator'));

View File

@ -944,6 +944,29 @@ class SiteTreeTest extends SapphireTest {
Config::inst()->update('SiteTree', 'meta_generator', $generator);
}
/**
* Tests SiteTree::MetaTags
* Note that this test makes no assumption on the closing of tags (other than <title></title>)
*/
public function testMetaTags() {
$this->logInWithPermission('ADMIN');
$page = $this->objFromFixture('Page', 'metapage');
// Test with title
$meta = $page->MetaTags();
$charset = Config::inst()->get('ContentNegotiator', 'encoding');
$this->assertContains('<meta http-equiv="Content-type" content="text/html; charset='.$charset.'"', $meta);
$this->assertContains('<meta name="description" content="The &lt;br /&gt; and &lt;br&gt; tags"', $meta);
$this->assertContains('<link rel="canonical" href="http://www.mysite.com/html-and-xml"', $meta);
$this->assertContains('<meta name="x-page-id" content="'.$page->ID.'"', $meta);
$this->assertContains('<meta name="x-cms-edit-link" content="'.$page->CMSEditLink().'" />', $meta);
$this->assertContains('<title>HTML &amp; XML</title>', $meta);
// Test without title
$meta = $page->MetaTags(false);
$this->assertNotContains('<title>', $meta);
}
/**
* Test that orphaned pages are handled correctly
*/

View File

@ -85,6 +85,10 @@ Page:
Title: Controller
numericonly:
Title: 1930
metapage:
Title: 'HTML & XML'
MetaDescription: 'The <br /> and <br> tags'
ExtraMeta: '<link rel="canonical" href="http://www.mysite.com/html-and-xml" />'
SiteTreeTest_Conflicted:
parent:
@ -101,4 +105,3 @@ RedirectorPage:
URLSegment: external
RedirectionType: External
ExternalURL: "http://www.google.com?a&b"