From 77dc826278efe092130ecc98a589d902b5e768ca Mon Sep 17 00:00:00 2001 From: Andrew Short Date: Tue, 13 Oct 2009 01:44:41 +0000 Subject: [PATCH] BUGFIX: Suppressed errors in SS_HTMLValue->setContent() so it can handle malformed HTML. MINOR: Added tests for saving and managing invalid HTML with SS_HTMLValue. From: Andrew Short git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88773 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- integration/HTMLValue.php | 17 ++++-------- tests/integration/HTMLValueTest.php | 41 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 12 deletions(-) create mode 100755 tests/integration/HTMLValueTest.php diff --git a/integration/HTMLValue.php b/integration/HTMLValue.php index ba9580fc3..ee38a6535 100755 --- a/integration/HTMLValue.php +++ b/integration/HTMLValue.php @@ -45,17 +45,10 @@ class SS_HTMLValue extends ViewableData { * @return bool */ public function setContent($content) { - //This is a patch to prevent invalid HTML returning warnings. - //Error messages are disabled, and then re-enabled - $old_level=error_reporting(); - error_reporting(0); - $value=$this->getDocument()->loadHTML( - '' . - "$content"); - error_reporting($old_level); - return $value; - - + return @$this->getDocument()->loadHTML( + '' . + "$content" + ); } /** @@ -82,4 +75,4 @@ class SS_HTMLValue extends ViewableData { return $this->getContent(); } -} \ No newline at end of file +} diff --git a/tests/integration/HTMLValueTest.php b/tests/integration/HTMLValueTest.php new file mode 100755 index 000000000..4a69b78bc --- /dev/null +++ b/tests/integration/HTMLValueTest.php @@ -0,0 +1,41 @@ +Enclosed Value

' => '

Enclosed Value

', + '

' => '

', + '' => '', + '/bodu>/body>' => '/bodu>/body>' + ); + + foreach($invalid as $input => $expected) { + $value->setContent($input); + $this->assertEquals($expected, $value->getContent(), 'Invalid HTML can be saved'); + } + } + + public function testInvalidHTMLTagNames() { + $value = new SS_HTMLValue(); + $invalid = array ( + '

', + '