]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Fix up edge case in nickname processing: overlong display forms should be rejected...
authorBrion Vibber <brion@pobox.com>
Fri, 31 Dec 2010 01:11:16 +0000 (17:11 -0800)
committerBrion Vibber <brion@pobox.com>
Fri, 31 Dec 2010 01:11:16 +0000 (17:11 -0800)
lib/nickname.php
tests/NicknameTest.php

index 562f1e2052897252558a309998ccb801e0a4d48a..4d3795e392231fe5a8bd9966f8f28f504dd847c7 100644 (file)
@@ -103,15 +103,17 @@ class Nickname
      */
     public static function normalize($str)
     {
+        if (mb_strlen($str) > self::MAX_LEN) {
+            // Display forms must also fit!
+            throw new NicknameTooLongException();
+        }
+
         $str = trim($str);
         $str = str_replace('_', '', $str);
         $str = mb_strtolower($str);
 
-        $len = mb_strlen($str);
-        if ($len < 1) {
+        if (mb_strlen($str) < 1) {
             throw new NicknameEmptyException();
-        } else if ($len > self::MAX_LEN) {
-            throw new NicknameTooLongException();
         }
         if (!self::isCanonical($str)) {
             throw new NicknameInvalidException();
index f49aeba602421957dae8e6e20e7656a520a46bf9..66e883c049f9cd40116e3f3971dd804a3c64e715 100644 (file)
@@ -33,9 +33,14 @@ class NicknameTest extends PHPUnit_Framework_TestCase
 
         if ($expected === false) {
             if ($expectedException) {
+                if ($exception) {
+                    $stuff = get_class($exception) . ': ' . $exception->getMessage();
+                } else {
+                    $stuff = var_export($exception, true);
+                }
                 $this->assertTrue($exception && $exception instanceof $expectedException,
                         "invalid input '$input' expected to fail with $expectedException, " .
-                        "got " . get_class($exception) . ': ' . $exception->getMessage());
+                        "got $stuff");
             } else {
                 $this->assertTrue($normalized == false,
                         "invalid input '$input' expected to fail");
@@ -104,7 +109,7 @@ class NicknameTest extends PHPUnit_Framework_TestCase
                      array('', false, 'NicknameEmptyException'),
                      array('___', false, 'NicknameEmptyException'),
                      array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'), // 64 chars
-                     array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee_', 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'), // the _ will be trimmed off, remaining valid
+                     array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee_', false, 'NicknameTooLongException'), // the _ is too long...
                      array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', false, 'NicknameTooLongException'), // 65 chars -- too long
                      );
     }