BUGFIX Ensure that \r carriage return characters get stripped out before setting content in HTMLValue::setContent(). DOMDocument will transform these into &#13 entities, which is apparently XML spec, but not necessary for us as we're using HTML

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@111949 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2010-10-12 10:02:21 +00:00 committed by Sam Minnee
parent ca53fbd49f
commit 1a9b527053
2 changed files with 7 additions and 7 deletions

View File

@ -45,11 +45,10 @@ class SS_HTMLValue extends ViewableData {
* @return bool
*/
public function setContent($content) {
// Ensure that window-style newlines don't get replaced with "
" entity by DOMDocument
if (PHP_EOL == "\n") {
$content = str_replace("\r\n", PHP_EOL, $content);
}
// Ensure that \r (carriage return) characters don't get replaced with "
" entity by DOMDocument
// apparently it's in the XML standard, but that messes it up because we're using HTML
$content = str_replace(chr(13), '', $content);
return @$this->getDocument()->loadHTML(
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>' .
"<body>$content</body></html>"

View File

@ -40,8 +40,9 @@ class SS_HTMLValueTest extends SapphireTest {
public function testMixedNewlines() {
$value = new SS_HTMLValue();
$eol = PHP_EOL;
$value->setContent("<p>paragraph</p>{$eol}<ul><li>1</li>\r\n</ul>");
$eol = "\n";
$platformEOL = PHP_EOL; // native EOL for platform. Windows is \r\n (CR-LF). UNIX is LF
$value->setContent("<p>paragraph</p>{$platformEOL}<ul><li>1</li>\r\n</ul>");
$this->assertEquals(
"<p>paragraph</p>{$eol}<ul><li>1</li>{$eol}</ul>",
$value->getContent(),