From d45b8cce8b57b6dee7124a49a5a6e088a493addc Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 11 Oct 2010 18:52:45 +0000 Subject: [PATCH] BUGFIX Ensure that windows-style newlines ("\r\n") don't get converted to their XML entity representation through DOMDocument in SS_HTMLValue->setContent() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@111878 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- integration/HTMLValue.php | 5 +++++ tests/integration/HTMLValueTest.php | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/integration/HTMLValue.php b/integration/HTMLValue.php index ee38a6535..312ba2807 100755 --- a/integration/HTMLValue.php +++ b/integration/HTMLValue.php @@ -45,6 +45,11 @@ 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); + } + return @$this->getDocument()->loadHTML( '' . "$content" diff --git a/tests/integration/HTMLValueTest.php b/tests/integration/HTMLValueTest.php index 4a69b78bc..0c984a8b3 100755 --- a/tests/integration/HTMLValueTest.php +++ b/tests/integration/HTMLValueTest.php @@ -38,4 +38,15 @@ class SS_HTMLValueTest extends SapphireTest { } } + public function testMixedNewlines() { + $value = new SS_HTMLValue(); + $eol = PHP_EOL; + $value->setContent("

paragraph

{$eol}"); + $this->assertEquals( + "

paragraph

{$eol}", + $value->getContent(), + 'Newlines get converted' + ); + } + } \ No newline at end of file