Fix up edge case in nickname processing: overlong display forms should be rejected before normalization (storage of display forms will also have fields with limited length)
This commit is contained in:
parent
63c95484bd
commit
80e2f4f529
|
@ -103,15 +103,17 @@ class Nickname
|
||||||
*/
|
*/
|
||||||
public static function normalize($str)
|
public static function normalize($str)
|
||||||
{
|
{
|
||||||
|
if (mb_strlen($str) > self::MAX_LEN) {
|
||||||
|
// Display forms must also fit!
|
||||||
|
throw new NicknameTooLongException();
|
||||||
|
}
|
||||||
|
|
||||||
$str = trim($str);
|
$str = trim($str);
|
||||||
$str = str_replace('_', '', $str);
|
$str = str_replace('_', '', $str);
|
||||||
$str = mb_strtolower($str);
|
$str = mb_strtolower($str);
|
||||||
|
|
||||||
$len = mb_strlen($str);
|
if (mb_strlen($str) < 1) {
|
||||||
if ($len < 1) {
|
|
||||||
throw new NicknameEmptyException();
|
throw new NicknameEmptyException();
|
||||||
} else if ($len > self::MAX_LEN) {
|
|
||||||
throw new NicknameTooLongException();
|
|
||||||
}
|
}
|
||||||
if (!self::isCanonical($str)) {
|
if (!self::isCanonical($str)) {
|
||||||
throw new NicknameInvalidException();
|
throw new NicknameInvalidException();
|
||||||
|
|
|
@ -33,9 +33,14 @@ class NicknameTest extends PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
if ($expected === false) {
|
if ($expected === false) {
|
||||||
if ($expectedException) {
|
if ($expectedException) {
|
||||||
|
if ($exception) {
|
||||||
|
$stuff = get_class($exception) . ': ' . $exception->getMessage();
|
||||||
|
} else {
|
||||||
|
$stuff = var_export($exception, true);
|
||||||
|
}
|
||||||
$this->assertTrue($exception && $exception instanceof $expectedException,
|
$this->assertTrue($exception && $exception instanceof $expectedException,
|
||||||
"invalid input '$input' expected to fail with $expectedException, " .
|
"invalid input '$input' expected to fail with $expectedException, " .
|
||||||
"got " . get_class($exception) . ': ' . $exception->getMessage());
|
"got $stuff");
|
||||||
} else {
|
} else {
|
||||||
$this->assertTrue($normalized == false,
|
$this->assertTrue($normalized == false,
|
||||||
"invalid input '$input' expected to fail");
|
"invalid input '$input' expected to fail");
|
||||||
|
@ -104,7 +109,7 @@ class NicknameTest extends PHPUnit_Framework_TestCase
|
||||||
array('', false, 'NicknameEmptyException'),
|
array('', false, 'NicknameEmptyException'),
|
||||||
array('___', false, 'NicknameEmptyException'),
|
array('___', false, 'NicknameEmptyException'),
|
||||||
array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'), // 64 chars
|
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
|
array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', false, 'NicknameTooLongException'), // 65 chars -- too long
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user