diff options
author | Dries Buytaert <dries@buytaert.net> | 2011-02-19 00:29:40 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2011-02-19 00:29:40 +0000 |
commit | 2143e4d3729ea2afe918545d80fc2d75d3e89485 (patch) | |
tree | 73c941944f29b49f1281a4cd57319cbd6a8e3db6 /modules | |
parent | acd8b039a3a59f94c7da0bdbd0a9aedec475b33d (diff) | |
download | brdo-2143e4d3729ea2afe918545d80fc2d75d3e89485.tar.gz brdo-2143e4d3729ea2afe918545d80fc2d75d3e89485.tar.bz2 |
- Patch #1063178 by Haza: line break filter will ignore everything following a <pre>xxx</pre>.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/filter/filter.module | 20 | ||||
-rw-r--r-- | modules/filter/filter.test | 21 |
2 files changed, 33 insertions, 8 deletions
diff --git a/modules/filter/filter.module b/modules/filter/filter.module index 24c64bd55..d66826b29 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -1590,11 +1590,12 @@ function _filter_autop($text) { // All block level tags $block = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|p|h[1-6]|hr)'; - // Split at opening and closing PRE, SCRIPT, STYLE, OBJECT tags and comments. - // We don't apply any processing to the contents of these tags to avoid messing - // up code. We look for matched pairs and allow basic nesting. For example: + // Split at opening and closing PRE, SCRIPT, STYLE, OBJECT, IFRAME tags + // and comments. We don't apply any processing to the contents of these tags + // to avoid messing up code. We look for matched pairs and allow basic + // nesting. For example: // "processed <pre> ignored <script> ignored </script> ignored </pre> processed" - $chunks = preg_split('@(<!--.*?-->|</?(?:pre|script|style|object|!--)[^>]*>)@i', $text, -1, PREG_SPLIT_DELIM_CAPTURE); + $chunks = preg_split('@(<!--.*?-->|</?(?:pre|script|style|object|iframe|!--)[^>]*>)@i', $text, -1, PREG_SPLIT_DELIM_CAPTURE); // Note: PHP ensures the array consists of alternating delimiters and literals // and begins and ends with a literal (inserting NULL as required). $ignore = FALSE; @@ -1602,9 +1603,14 @@ function _filter_autop($text) { $output = ''; foreach ($chunks as $i => $chunk) { if ($i % 2) { - // Opening or closing tag? - $open = ($chunk[1] != '/' || $chunk[1] != '!'); $comment = (substr($chunk, 0, 4) == '<!--'); + if ($comment) { + // Nothing to do, this is a comment. + $output .= $chunk; + continue; + } + // Opening or closing tag? + $open = ($chunk[1] != '/'); list($tag) = preg_split('/[ >]/', substr($chunk, 2 - $open), 2); if (!$ignore) { if ($open) { @@ -1613,7 +1619,7 @@ function _filter_autop($text) { } } // Only allow a matching tag to close it. - elseif ((!$open && $ignoretag == $tag) || $comment) { + elseif (!$open && $ignoretag == $tag) { $ignore = FALSE; $ignoretag = ''; } diff --git a/modules/filter/filter.test b/modules/filter/filter.test index e8b8058c4..cb12ec9f5 100644 --- a/modules/filter/filter.test +++ b/modules/filter/filter.test @@ -833,6 +833,25 @@ class FilterUnitTestCase extends DrupalUnitTestCase { '<blockquote><pre>aaa</pre></blockquote>' => array( "<blockquote><pre>aaa</pre></blockquote>" => TRUE, ), + "<pre>aaa\nbbb\nccc</pre>\nddd\neee" => array( + "<pre>aaa\nbbb\nccc</pre>" => TRUE, + "<p>ddd<br />\neee</p>" => TRUE, + ), + // Comments remain unchanged and subsequent lines/paragraphs are + // transformed normally. + "aaa<!--comment-->\n\nbbb\n\nccc\n\nddd<!--comment\nwith linebreak-->\n\neee\n\nfff" => array( + "<p>aaa</p>\n<!--comment--><p>\nbbb</p>\n<p>ccc</p>\n<p>ddd</p>" => TRUE, + "<!--comment\nwith linebreak--><p>\neee</p>\n<p>fff</p>" => TRUE, + ), + // Check that a comment in a PRE will result that the text after + // the comment, but still in PRE, is not transformed. + "<pre>aaa\nbbb<!-- comment -->\n\nccc</pre>\nddd" => array( + "<pre>aaa\nbbb<!-- comment -->\n\nccc</pre>" => TRUE, + ), + // Bug 810824, paragraphs were appearing around iframe tags. + "<iframe>aaa</iframe>\n\n" => array( + "<p><iframe>aaa</iframe></p>" => FALSE, + ), ); $this->assertFilteredString($filter, $tests); @@ -1464,7 +1483,7 @@ www.example.com with a newline in comments --> if (!$success) { $this->verbose('Source:<pre>' . check_plain(var_export($source, TRUE)) . '</pre>' . '<hr />' . 'Result:<pre>' . check_plain(var_export($result, TRUE)) . '</pre>' - . '<hr />' . ($is_expected ? 'Found:' : 'Not found:') + . '<hr />' . ($is_expected ? 'Expected:' : 'Not expected:') . '<pre>' . check_plain(var_export($value, TRUE)) . '</pre>' ); } |