Commit fa0641ba authored by alexpott's avatar alexpott

Issue #2274795 by Wim Leers | chx: Simplify (and defuse) the filter skipping code.

parent edba6610
......@@ -362,11 +362,6 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE,
return '';
}
// Prevent FilterInterface::TYPE_HTML_RESTRICTOR from being skipped.
if (in_array(FilterInterface::TYPE_HTML_RESTRICTOR, $filter_types_to_skip)) {
$filter_types_to_skip = array_diff($filter_types_to_skip, array(FilterInterface::TYPE_HTML_RESTRICTOR));
}
// When certain filters should be skipped, don't perform caching.
if ($filter_types_to_skip) {
$cache = FALSE;
......@@ -389,24 +384,24 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE,
// Get a complete list of filters, ordered properly.
$filters = $format->filters();
$filter_must_be_applied = function($filter) use ($filter_types_to_skip) {
$enabled = $filter->status === TRUE;
$type = $filter->getType();
// Prevent FilterInterface::TYPE_HTML_RESTRICTOR from being skipped.
$filter_type_must_be_applied = $type == FilterInterface::TYPE_HTML_RESTRICTOR || !in_array($type, $filter_types_to_skip);
return $enabled && $filter_type_must_be_applied;
};
// Give filters the chance to escape HTML-like data such as code or formulas.
foreach ($filters as $filter) {
// If necessary, skip filters of a certain type.
if (in_array($filter->getType(), $filter_types_to_skip)) {
continue;
}
if ($filter->status) {
if ($filter_must_be_applied($filter)) {
$text = $filter->prepare($text, $langcode, $cache, $cache_id);
}
}
// Perform filtering.
foreach ($filters as $filter) {
// If necessary, skip filters of a certain type.
if (in_array($filter->getType(), $filter_types_to_skip)) {
continue;
}
if ($filter->status) {
if ($filter_must_be_applied($filter)) {
$text = $filter->process($text, $langcode, $cache, $cache_id);
}
}
......
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