TemplateHelper: silent workaround for 5.3 for d76904a

This commit is contained in:
Denis Sokolov
2014-03-30 18:52:42 +02:00
parent d76904a0d8
commit 35115f7e7f
2 changed files with 13 additions and 1 deletions
+9 -1
View File
@@ -25,7 +25,15 @@ class TemplateHelper
*/
public function escape($raw)
{
return htmlspecialchars($raw, ENT_QUOTES | ENT_SUBSTITUTE, "UTF-8");
$flags = ENT_QUOTES;
// On 5.3 this will return an empty string if the source contents
// are illegal UTF-8 sequences. Oh well, 5.3.
if (defined('ENT_SUBSTITUTE')) {
$flags |= ENT_SUBSTITUTE;
}
return htmlspecialchars($raw, $flags, "UTF-8");
}
/**
+4
View File
@@ -39,6 +39,10 @@ class TemplateHelperTest extends TestCase
public function testEscapeBrokenUtf8()
{
if (version_compare(PHP_VERSION, '5.4', '<')) {
return $this->markTestSkipped();
}
// The following includes an illegal utf-8 sequence to test.
// Encoded in base64 to survive possible encoding changes of this file.
$original = base64_decode('VGhpcyBpcyBhbiBpbGxlZ2FsIHV0Zi04IHNlcXVlbmNlOiDD');