Skip to content
Snippets Groups Projects
Commit fa0641ba authored by Alex Pott's avatar Alex Pott
Browse files

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

parent edba6610
No related branches found
No related tags found
No related merge requests found
...@@ -362,11 +362,6 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE, ...@@ -362,11 +362,6 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE,
return ''; 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. // When certain filters should be skipped, don't perform caching.
if ($filter_types_to_skip) { if ($filter_types_to_skip) {
$cache = FALSE; $cache = FALSE;
...@@ -389,24 +384,24 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE, ...@@ -389,24 +384,24 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE,
// Get a complete list of filters, ordered properly. // Get a complete list of filters, ordered properly.
$filters = $format->filters(); $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. // Give filters the chance to escape HTML-like data such as code or formulas.
foreach ($filters as $filter) { foreach ($filters as $filter) {
// If necessary, skip filters of a certain type. if ($filter_must_be_applied($filter)) {
if (in_array($filter->getType(), $filter_types_to_skip)) {
continue;
}
if ($filter->status) {
$text = $filter->prepare($text, $langcode, $cache, $cache_id); $text = $filter->prepare($text, $langcode, $cache, $cache_id);
} }
} }
// Perform filtering. // Perform filtering.
foreach ($filters as $filter) { foreach ($filters as $filter) {
// If necessary, skip filters of a certain type. if ($filter_must_be_applied($filter)) {
if (in_array($filter->getType(), $filter_types_to_skip)) {
continue;
}
if ($filter->status) {
$text = $filter->process($text, $langcode, $cache, $cache_id); $text = $filter->process($text, $langcode, $cache, $cache_id);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment