Commit f36b87d1 authored by Dries's avatar Dries

- Patch #721536 by JacobSingh, jpmckinney, Damien Tournoud, David_Rothstein:...

- Patch #721536 by JacobSingh, jpmckinney, Damien Tournoud, David_Rothstein: HTML corrector filter has problems with unescaped CDATA and incorrectly closed tags.
parent c8048163
......@@ -309,11 +309,11 @@ class TextSummaryTestCase extends DrupalWebTestCase {
$expected_lb = array(
"<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>",
"",
"<p />",
"<p />",
"<p />",
"<p />",
"<p />",
"<p></p>",
"<p></p>",
"<p></p>",
"<p></p>",
"<p></p>",
"<p>\nHi</p>",
"<p>\nHi</p>",
"<p>\nHi</p>",
......
......@@ -983,7 +983,7 @@ function _filter_tips($format_id, $long = FALSE) {
*/
function filter_dom_load($text) {
// Ignore warnings during HTML soup loading.
$dom_document = @DOMDocument::loadHTML('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $text . '</body></html>');
$dom_document = @DOMDocument::loadHTML('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $text . '</body></html>');
return $dom_document;
}
......@@ -1018,7 +1018,7 @@ function filter_dom_serialize($dom_document) {
foreach ($body_node->childNodes as $child_node) {
$body_content .= $dom_document->saveXML($child_node);
}
return preg_replace('|<([^>]*)/>|i', '<$1 />', $body_content);
return preg_replace('|<([^> ]*)/>|i', '<$1 />', $body_content);
}
/**
......
......@@ -1003,7 +1003,7 @@ class FilterUnitTestCase extends DrupalUnitTestCase {
$this->assertEqual($f, '<p>text</p>', t('HTML corrector -- tag closing at the end of input.'));
$f = _filter_htmlcorrector('<p>text<p><p>text');
$this->assertEqual($f, '<p>text</p><p /><p>text</p>', t('HTML corrector -- tag closing.'));
$this->assertEqual($f, '<p>text</p><p></p><p>text</p>', t('HTML corrector -- tag closing.'));
$f = _filter_htmlcorrector("<ul><li>e1<li>e2");
$this->assertEqual($f, "<ul><li>e1</li><li>e2</li></ul>", t('HTML corrector -- unclosed list tags.'));
......@@ -1021,14 +1021,17 @@ class FilterUnitTestCase extends DrupalUnitTestCase {
$f = _filter_htmlcorrector('<P>test</p>');
$this->assertEqual($f, '<p>test</p>', t('HTML corrector -- Convert uppercased tags to proper lowercased ones.'));
$f = _filter_htmlcorrector('test<hr />');
$this->assertEqual($f, 'test<hr />', t('HTML corrector -- Let proper XHTML pass through.'));
$f = _filter_htmlcorrector('test<hr/>');
$this->assertEqual($f, 'test<hr />', t('HTML corrector -- Let proper XHTML pass thru.'));
$this->assertEqual($f, 'test<hr />', t('HTML corrector -- Let proper XHTML pass through, but ensure there is a single space before the closing slash.'));
$f = _filter_htmlcorrector('test<hr />');
$this->assertEqual($f, 'test<hr />', t('HTML corrector -- Let proper XHTML pass thru.'));
$f = _filter_htmlcorrector('test<hr />');
$this->assertEqual($f, 'test<hr />', t('HTML corrector -- Let proper XHTML pass through, but ensure there are not too many spaces before the closing slash.'));
$f = _filter_htmlcorrector('<span class="test" />');
$this->assertEqual($f, '<span class="test" />', t('HTML corrector -- Let proper XHTML pass thru.'));
$this->assertEqual($f, '<span class="test"></span>', t('HTML corrector -- Convert XHTML that is properly formed but that would not be compatible with typical HTML user agents.'));
$f = _filter_htmlcorrector('test1<br class="test">test2');
$this->assertEqual($f, 'test1<br class="test" />test2', t('HTML corrector -- Automatically close single tags.'));
......@@ -1042,6 +1045,12 @@ class FilterUnitTestCase extends DrupalUnitTestCase {
$f = _filter_htmlcorrector('<img src="http://example.com/test.jpg">test</img>');
$this->assertEqual($f, '<img src="http://example.com/test.jpg" />test', t('HTML corrector -- Automatically close single tags.'));
$f = _filter_htmlcorrector('<br></br>');
$this->assertEqual($f, '<br />', t("HTML corrector -- Transform empty tags to a single closed tag if the tag's content model is EMPTY."));
$f = _filter_htmlcorrector('<div></div>');
$this->assertEqual($f, '<div></div>', t("HTML corrector -- Do not transform empty tags to a single closed tag if the tag's content model is not EMPTY."));
$f = _filter_htmlcorrector('<p>line1<br/><hr/>line2</p>');
$this->assertEqual($f, '<p>line1<br /></p><hr />line2', t('HTML corrector -- Move non-inline elements outside of inline containers.'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment