mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX Ensure that windows-style newlines ("\r\n") don't get converted to their XML entity representation through DOMDocument in SS_HTMLValue->setContent() (from r111878)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112935 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
fd7babe5a0
commit
f51f5bc958
@ -45,6 +45,11 @@ class SS_HTMLValue extends ViewableData {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function setContent($content) {
|
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(
|
return @$this->getDocument()->loadHTML(
|
||||||
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>' .
|
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>' .
|
||||||
"<body>$content</body></html>"
|
"<body>$content</body></html>"
|
||||||
|
@ -38,4 +38,15 @@ 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>");
|
||||||
|
$this->assertEquals(
|
||||||
|
"<p>paragraph</p>{$eol}<ul><li>1</li>{$eol}</ul>",
|
||||||
|
$value->getContent(),
|
||||||
|
'Newlines get converted'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user