1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 03:40:37 +02:00

Fix for <title> tag containing single or double quotes. Tests added.

This commit is contained in:
Cameron
2021-11-03 13:55:56 -07:00
parent 6d5b4f5c3a
commit 54cb89b87d
2 changed files with 276 additions and 2 deletions

View File

@@ -4473,8 +4473,14 @@ class eResponse
$meta = '_' . $meta;
if(isset($this->$meta) && !empty($content))
{
$content = str_replace(array('&amp;', '"', "'"), array('&', '', ''), $content);
$this->{$meta}[] = htmlspecialchars((string) $content, ENT_QUOTES, 'UTF-8');
$content = str_replace('&amp;', '&', $content);
if($meta !== '_e_PAGETITLE')
{
$content = htmlspecialchars((string) $content, ENT_QUOTES, 'UTF-8');
}
$this->{$meta}[] = $content;
}
return $this;
}
@@ -4518,6 +4524,8 @@ class eResponse
$this->_e_PAGETITLE = array();
}
$title = str_replace(['&#39;','&#039;'], "'", $title);
return $this->addMetaData('e_PAGETITLE', $title);
}

View File

@@ -0,0 +1,266 @@
<?php
class eResponseTest extends \Codeception\Test\Unit
{
/** @var eResponse */
protected $er;
protected function _before()
{
try
{
$this->er = $this->make('eResponse');
}
catch(Exception $e)
{
$this->assertTrue(false, $e->getMessage());
}
}
/*
public function testGetRobotDescriptions()
{
}
public function testSetParams()
{
}
public function testGetMetaData()
{
}
public function testGetMetaDescription()
{
}
public function testSetParam()
{
}
*/
public function testAddMeta()
{
$title = "Admin's Blog Title";
$this->er->addMeta('og:title', $title);
$result = $this->er->getMeta('og:title');
$expected = array (
'og:title' =>
array (
'property' => 'og:title',
'content' => "Admin's Blog Title",
),
);
$this->assertSame($expected, $result);
}
/*
public function testAddMetaDescription()
{
}
public function testGetRenderMod()
{
}
public function testIsParam()
{
}
public function testSetContentType()
{
}
public function testGetTitle()
{
}
public function testRemoveMeta()
{
}
public function testSetMeta()
{
}
public function testSetRenderMod()
{
}
public function testAppendTitle()
{
}
public function testPrependBody()
{
}
public function testPrependTitle()
{
}
public function testGetParam()
{
}
public function testAddMetaKeywords()
{
}
public function testGetMeta()
{
}
public function testGetBody()
{
}
public function testSendContentType()
{
}
public function testGetRobotTypes()
{
}
*/
public function testAddMetaData()
{
$title = "Admin's Blog Title";
$this->er->addMetaData('e_PAGETITLE', $title);
$result = $this->er->getMetaData('e_PAGETITLE');
$this->assertSame("Admin's Blog Title", $result);
$title = ' - "Quote"';
$this->er->addMetaData('e_PAGETITLE', $title);
$result = $this->er->getMetaData('e_PAGETITLE');
$this->assertSame("Admin's Blog Title - \"Quote\"", $result);
}
/*
public function testSendJson()
{
}
public function testGetJs()
{
}
public function testGetContentMediaType()
{
}
public function testSetTitle()
{
}
public function testGetMetaKeywords()
{
}
public function testAddContentType()
{
}
public function testGetMetaTitle()
{
}
public function testSendMeta()
{
}
public function testAddHeader()
{
}
public function testAppendBody()
{
}
public function testGetContentType()
{
}
public function testRenderMeta()
{
}
public function testSend()
{
}
public function testSetBody()
{
}
*/
public function testAddMetaTitle()
{
$title = 'Admin&#39;s Blog Title';
$this->er->addMetaTitle($title);
$result = $this->er->getMetaTitle();
$this->assertSame("Admin's Blog Title", $result);
$title = ' "quote"';
$this->er->addMetaTitle($title);
$result = $this->er->getMetaTitle();
$this->assertSame("Admin's Blog Title - \"quote\"", $result);
$title = 'Cam&#039;s Fixed &quot;Meta&quot;';
$this->er->addMetaTitle($title, true);
$result = $this->er->getMetaTitle();
$this->assertSame("Cam's Fixed &quot;Meta&quot;", $result);
}
}