]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/nickname.php
Fix up edge case in nickname processing: overlong display forms should be rejected...
[quix0rs-gnu-social.git] / lib / nickname.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();