Commit 2143e4d3 authored by Dries's avatar Dries

- Patch #1063178 by Haza: line break filter will ignore everything following a <pre>xxx</pre>.

parent acd8b039
......@@ -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 = '';
}
......
......@@ -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>'
);
}
......
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