PluginOutput: Transform newlines first and purify HTML afterwards
fixes #4686
This commit is contained in:
parent
dd7f418b48
commit
48e0f1bd1f
|
@ -88,16 +88,18 @@ class Zend_View_Helper_PluginOutput extends Zend_View_Helper_Abstract
|
||||||
if (empty($output)) {
|
if (empty($output)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($command !== null) {
|
if ($command !== null) {
|
||||||
$output = $this->hookRenderer->render($command, $output, ! $raw);
|
$output = $this->hookRenderer->render($command, $output, ! $raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preg_match('~<\w+(?>\s\w+=[^>]*)?>~', $output)) {
|
if (preg_match('~<\w+(?>\s\w+=[^>]*)?>~', $output)) {
|
||||||
// HTML
|
// HTML
|
||||||
$output = preg_replace(
|
$output = HtmlPurifier::process(preg_replace(
|
||||||
self::$htmlPatterns,
|
self::$htmlPatterns,
|
||||||
self::$htmlReplacements,
|
self::$htmlReplacements,
|
||||||
HtmlPurifier::process($output)
|
$output
|
||||||
);
|
));
|
||||||
$isHtml = true;
|
$isHtml = true;
|
||||||
} else {
|
} else {
|
||||||
// Plaintext
|
// Plaintext
|
||||||
|
@ -109,6 +111,7 @@ class Zend_View_Helper_PluginOutput extends Zend_View_Helper_Abstract
|
||||||
);
|
);
|
||||||
$isHtml = false;
|
$isHtml = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = trim($output);
|
$output = trim($output);
|
||||||
// Add zero-width space after commas which are not followed by a whitespace character
|
// Add zero-width space after commas which are not followed by a whitespace character
|
||||||
// in oder to help browsers to break words in plugin output
|
// in oder to help browsers to break words in plugin output
|
||||||
|
@ -121,6 +124,7 @@ class Zend_View_Helper_PluginOutput extends Zend_View_Helper_Abstract
|
||||||
$output = '<div class="plugin-output preformatted">' . $output . '</div>';
|
$output = '<div class="plugin-output preformatted">' . $output . '</div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,4 +152,24 @@ class PluginOutputTest extends BaseTestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNewlineProcessingInHtmlOutput()
|
||||||
|
{
|
||||||
|
$this->checkHtmlOutput(
|
||||||
|
'This is plugin output\n\n<ul>\n <li>with a HTML list</li>\n</ul>\n\n'
|
||||||
|
. 'and more text that\nis split onto multiple\n\nlines',
|
||||||
|
<<<HTML
|
||||||
|
This is plugin output
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>with a HTML list</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
and more text that
|
||||||
|
is split onto multiple
|
||||||
|
|
||||||
|
lines
|
||||||
|
HTML
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue