Merge branch 'w24_MDL-39096_m26_obfuscate' of git://github.com/skodak/moodle
This commit is contained in:
@@ -106,6 +106,22 @@ class web_testcase extends advanced_testcase {
|
||||
format_text_email('習習',FORMAT_HTML));
|
||||
}
|
||||
|
||||
function test_obfuscate_email() {
|
||||
$email = '[email protected]';
|
||||
$obfuscated = obfuscate_email($email);
|
||||
$this->assertNotSame($email, $obfuscated);
|
||||
$back = textlib::entities_to_utf8(urldecode($email), true);
|
||||
$this->assertSame($email, $back);
|
||||
}
|
||||
|
||||
function test_obfuscate_text() {
|
||||
$text = 'Žluťoučký koníček 32131';
|
||||
$obfuscated = obfuscate_text($text);
|
||||
$this->assertNotSame($text, $obfuscated);
|
||||
$back = textlib::entities_to_utf8($obfuscated, true);
|
||||
$this->assertSame($text, $back);
|
||||
}
|
||||
|
||||
function test_highlight() {
|
||||
$this->assertEquals(highlight('good', 'This is good'), 'This is <span class="highlight">good</span>');
|
||||
$this->assertEquals(highlight('SpaN', 'span'), '<span class="highlight">span</span>');
|
||||
|
||||
+7
-6
@@ -2594,19 +2594,20 @@ function redirect($url, $message='', $delay=-1) {
|
||||
function obfuscate_text($plaintext) {
|
||||
|
||||
$i=0;
|
||||
$length = strlen($plaintext);
|
||||
$length = textlib::strlen($plaintext);
|
||||
$obfuscated='';
|
||||
$prev_obfuscated = false;
|
||||
while ($i < $length) {
|
||||
$c = ord($plaintext{$i});
|
||||
$numerical = ($c >= ord('0')) && ($c <= ord('9'));
|
||||
$char = textlib::substr($plaintext, $i, 1);
|
||||
$ord = textlib::utf8ord($char);
|
||||
$numerical = ($ord >= ord('0')) && ($ord <= ord('9'));
|
||||
if ($prev_obfuscated and $numerical ) {
|
||||
$obfuscated.='&#'.ord($plaintext{$i}).';';
|
||||
$obfuscated.='&#'.$ord.';';
|
||||
} else if (rand(0,2)) {
|
||||
$obfuscated.='&#'.ord($plaintext{$i}).';';
|
||||
$obfuscated.='&#'.$ord.';';
|
||||
$prev_obfuscated = true;
|
||||
} else {
|
||||
$obfuscated.=$plaintext{$i};
|
||||
$obfuscated.=$char;
|
||||
$prev_obfuscated = false;
|
||||
}
|
||||
$i++;
|
||||
|
||||
Reference in New Issue
Block a user