mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 13:33:52 +02:00
Merge branch 'MDL-82702-main' of https://github.com/andrewnicols/moodle
This commit is contained in:
commit
daed5e02a1
@ -39,12 +39,10 @@ class text_filter extends \core_filters\text_filter {
|
||||
|
||||
// Pattern to find a mailto link with the linked text.
|
||||
$pattern = '|(<a\s+href\s*=\s*[\'"]?mailto:)' . $emailregex . '([\'"]?\s*>)' . '(.*)' . '(</a>)|iU';
|
||||
$text = preg_replace_callback($pattern, 'filter_emailprotect_alter_mailto', $text);
|
||||
$text = preg_replace_callback($pattern, [self::class, 'alter_mailto'], $text);
|
||||
|
||||
// Pattern to find any other email address in the text.
|
||||
$pattern = '/(^|\s+|>)' . $emailregex . '($|\s+|\.\s+|\.$|<)/i';
|
||||
$text = preg_replace_callback($pattern, 'filter_emailprotect_alter_email', $text);
|
||||
$text = preg_replace_callback($pattern, [self::class, 'alter_email'], $text);
|
||||
|
||||
return $text;
|
||||
@ -57,7 +55,7 @@ class text_filter extends \core_filters\text_filter {
|
||||
* @return string
|
||||
*/
|
||||
private function alter_email($matches) {
|
||||
return $matches[1].obfuscate_text($matches[2]).$matches[3];
|
||||
return $matches[1] . obfuscate_text($matches[2]) . $matches[3];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,9 +36,18 @@ final class text_filter_test extends \advanced_testcase {
|
||||
public function test_filter(
|
||||
string $expression,
|
||||
string $text,
|
||||
bool $exactmatch,
|
||||
): void {
|
||||
$filter = new text_filter(\core\context\system::instance(), []);
|
||||
$this->assertMatchesRegularExpression($expression, $text);
|
||||
$result = $filter->filter($text);
|
||||
|
||||
$this->assertMatchesRegularExpression($expression, $result);
|
||||
|
||||
if ($exactmatch) {
|
||||
$this->assertEquals($text, $result);
|
||||
} else {
|
||||
$this->assertNotEquals($text, $result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,11 +59,23 @@ final class text_filter_test extends \advanced_testcase {
|
||||
$email = 'chaise@example.com';
|
||||
return [
|
||||
// No email address found.
|
||||
['/Hello, world!/', 'Hello, world!'],
|
||||
[
|
||||
'/Hello, world!/',
|
||||
'Hello, world!',
|
||||
true,
|
||||
],
|
||||
// Email addresses present.
|
||||
// Note: The obfuscation randomly choose which chars to obfuscate.
|
||||
['/.*@.*/', $email],
|
||||
["~<a href='mailto:.*@.*'>.*@.*</a>~", "<a href='mailto:$email'>$email</a>"],
|
||||
[
|
||||
'/.*(@|@).*/',
|
||||
$email,
|
||||
false,
|
||||
],
|
||||
[
|
||||
"~<a href=\".*:.*(@|@).*\">.*(@|@).*</a>~",
|
||||
"<a href='mailto:$email'>$email</a>",
|
||||
false,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user