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 ( + '

', + '
', + '""\'\'\'"""\'""<<<>/' + ); + + foreach($invalid as $input) { + $value->setContent($input); + $this->assertEquals ( + 'test-link', + $value->getElementsByTagName('a')->item(0)->getAttribute('href'), + 'Link data can be extraced from malformed HTML' + ); + } + } + +} \ No newline at end of file