From f0dc6c65cad90f0b25743c995a54874785467664 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 19 Oct 2010 05:07:27 +0000 Subject: [PATCH] BUGFIX Ensure that \r carriage return characters get stripped out before setting content in HTMLValue::setContent(). DOMDocument will transform these into entities, which is apparently XML spec, but not necessary for us as we're using HTML (from r111949) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112946 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- integration/HTMLValue.php | 9 ++++----- tests/integration/HTMLValueTest.php | 5 +++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/integration/HTMLValue.php b/integration/HTMLValue.php index 312ba2807..735d749b4 100755 --- a/integration/HTMLValue.php +++ b/integration/HTMLValue.php @@ -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( '' . "$content" diff --git a/tests/integration/HTMLValueTest.php b/tests/integration/HTMLValueTest.php index 0c984a8b3..ecfe46c0d 100755 --- a/tests/integration/HTMLValueTest.php +++ b/tests/integration/HTMLValueTest.php @@ -40,8 +40,9 @@ class SS_HTMLValueTest extends SapphireTest { public function testMixedNewlines() { $value = new SS_HTMLValue(); - $eol = PHP_EOL; - $value->setContent("

paragraph

{$eol}"); + $eol = "\n"; + $platformEOL = PHP_EOL; // native EOL for platform. Windows is \r\n (CR-LF). UNIX is LF + $value->setContent("

paragraph

{$platformEOL}"); $this->assertEquals( "

paragraph

{$eol}", $value->getContent(),