Skip to content

Commit

Permalink
Add minimum length for nicknames
Browse files Browse the repository at this point in the history
  • Loading branch information
RedEnchilada committed Aug 1, 2014
1 parent 9ea7a6e commit 878d734
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions lib/nickname.php
Expand Up @@ -68,6 +68,7 @@ class Nickname
/**
* Maximum number of characters in a canonical-form nickname.
*/
const MIN_LEN = 3;
const MAX_LEN = 64;

/**
Expand Down Expand Up @@ -108,13 +109,18 @@ public static function normalize($str)
throw new NicknameTooLongException();
}

if (mb_strlen($str) < self::MIN_LEN) {
// Display forms must also fit!
throw new NicknameTooShortException();
}

$str = trim($str);
$str = str_replace('_', '', $str);
$str = mb_strtolower($str);

/*
if (mb_strlen($str) < 1) {
throw new NicknameEmptyException();
}
}*/
if (!self::isCanonical($str)) {
throw new NicknameInvalidException();
}
Expand Down Expand Up @@ -179,6 +185,22 @@ protected function defaultMessage()
}
}

class NicknameTooShortException extends NicknameInvalidException
{
/**
* Default localized message for this type of exception.
* @return string
*/
protected function defaultMessage()
{
// TRANS: Validation error in form for registration, profile and group settings, etc.
return sprintf(_m('Nickname cannot be less than %d character long.',
'Nickname cannot be less than %d characters long.',
Nickname::MIN_LEN),
Nickname::MIN_LEN);
}
}

class NicknameTooLongException extends NicknameInvalidException
{
/**
Expand Down

0 comments on commit 878d734

Please sign in to comment.