]> git.mjollnir.org Git - moodle.git/commitdiff
Fixes for obfuscate_text() when printing emails with numbers in them.
authormoodler <moodler>
Tue, 9 Sep 2003 02:22:36 +0000 (02:22 +0000)
committermoodler <moodler>
Tue, 9 Sep 2003 02:22:36 +0000 (02:22 +0000)
(Patch from Zbigniew Fiedorowicz  - thanks)

lib/weblib.php

index 68ad3c1a8e783ce84f68eceb373d6e38e849789f..fdc77a3b8646edc3581f63a687bd3ca9a2a172d8 100644 (file)
@@ -1605,13 +1605,20 @@ function obfuscate_text($plaintext) {
     $i=0;
     $length = strlen($plaintext);
     $obfuscated="";
+    $prev_obfuscated = false;
     while ($i < $length) {
-        if (rand(0,2)) {
+        $c = ord($plaintext{$i});
+        $numerical = ($c >= ord('0')) && ($c <= ord('9'));
+        if ($prev_obfuscated and $numerical ) {
+            $obfuscated.='&#'.ord($plaintext{$i});
+        } else if (rand(0,2)) {
             $obfuscated.='&#'.ord($plaintext{$i});
+            $prev_obfuscated = true;
         } else {
             $obfuscated.=$plaintext{$i};
+            $prev_obfuscated = false;
         }
-        $i++;
+      $i++;
     }
     return $obfuscated;
 }