mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
Merge branch 'MDL-42638-master' of https://github.com/lucaboesch/moodle
This commit is contained in:
commit
d6c704bf8e
@ -104,14 +104,14 @@ class filter_emoticon extends moodle_text_filter {
|
||||
}
|
||||
|
||||
// Detect all zones that we should not handle (including the nested tags).
|
||||
$processing = preg_split('/(<\/?(?:span|script)[^>]*>)/is', $text, 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
$processing = preg_split('/(<\/?(?:span|script|pre)[^>]*>)/is', $text, 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
// Initialize the results.
|
||||
$resulthtml = "";
|
||||
$exclude = 0;
|
||||
|
||||
// Define the patterns that mark the start of the forbidden zones.
|
||||
$excludepattern = array('/^<script/is', '/^<span[^>]+class="nolink[^"]*"/is');
|
||||
$excludepattern = array('/^<script/is', '/^<span[^>]+class="nolink[^"]*"/is', '/^<pre/is');
|
||||
|
||||
// Loop through the fragments.
|
||||
foreach ($processing as $fragment) {
|
||||
@ -126,13 +126,15 @@ class filter_emoticon extends moodle_text_filter {
|
||||
}
|
||||
if ($exclude > 0) {
|
||||
// If we are ignoring the fragment, then we must check if we may have reached the end of the zone.
|
||||
if (strpos($fragment, '</span') !== false || strpos($fragment, '</script') !== false) {
|
||||
if (strpos($fragment, '</span') !== false || strpos($fragment, '</script') !== false
|
||||
|| strpos($fragment, '</pre') !== false) {
|
||||
$exclude -= 1;
|
||||
// This is needed because of a double increment at the first element.
|
||||
if ($exclude == 1) {
|
||||
$exclude -= 1;
|
||||
}
|
||||
} else if (strpos($fragment, '<span') !== false || strpos($fragment, '<script') !== false) {
|
||||
} else if (strpos($fragment, '<span') !== false || strpos($fragment, '<script') !== false
|
||||
|| strpos($fragment, '<pre') !== false) {
|
||||
// If we find a nested tag we increase the exclusion level.
|
||||
$exclude = $exclude + 1;
|
||||
}
|
||||
|
@ -95,6 +95,21 @@ class filter_emoticon_testcase extends advanced_testcase {
|
||||
'format' => FORMAT_HTML,
|
||||
'expected' => '<span class="nolink"><span>(n)</span>(n)</span>' . $this->get_converted_content_for_emoticon('(n)'),
|
||||
],
|
||||
'Basic pre should not be processed' => [
|
||||
'input' => '<pre>(n)</pre>',
|
||||
'format' => FORMAT_HTML,
|
||||
'expected' => '<pre>(n)</pre>',
|
||||
],
|
||||
'Nested pre should not be processed' => [
|
||||
'input' => '<pre><pre>(n)</pre>(n)</pre>',
|
||||
'format' => FORMAT_HTML,
|
||||
'expected' => '<pre><pre>(n)</pre>(n)</pre>',
|
||||
],
|
||||
'Nested pre should not be processed but following emoticon' => [
|
||||
'input' => '<pre><pre>(n)</pre>(n)</pre>(n)',
|
||||
'format' => FORMAT_HTML,
|
||||
'expected' => '<pre><pre>(n)</pre>(n)</pre>' . $this->get_converted_content_for_emoticon('(n)'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user