Skip to content
Browse files

Merge branch 'w24_MDL-39096_m25_obfuscate' of git://github.com/skodak…

…/moodle into MOODLE_25_STABLE
  • Loading branch information...
2 parents 9d1a909 + 06de509 commit 7f9f03442a2ace327340a058f456752246be9e66 @danpoltawski danpoltawski committed
Showing with 23 additions and 6 deletions.
  1. +16 −0 lib/tests/weblib_test.php
  2. +7 −6 lib/weblib.php
View
16 lib/tests/weblib_test.php
@@ -106,6 +106,22 @@ function test_format_text_email() {
format_text_email('習習',FORMAT_HTML));
}
+ function test_obfuscate_email() {
+ $email = 'some.user@example.com';
+ $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>');
View
13 lib/weblib.php
@@ -2594,19 +2594,20 @@ function obfuscate_email($email) {
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++;

0 comments on commit 7f9f034

Please sign in to comment.
Something went wrong with that request. Please try again.