forked from GNUsocial/gnu-social
[NICKNAME] Don't throw when normalizing reserved nicknames
This commit is contained in:
parent
637c25d5fe
commit
079d230959
@ -22,6 +22,7 @@
|
|||||||
namespace App\Util;
|
namespace App\Util;
|
||||||
|
|
||||||
use App\Core\DB\DB;
|
use App\Core\DB\DB;
|
||||||
|
use App\Core\Log;
|
||||||
use App\Entity\GSActor;
|
use App\Entity\GSActor;
|
||||||
use App\Entity\LocalGroup;
|
use App\Entity\LocalGroup;
|
||||||
use App\Entity\LocalUser;
|
use App\Entity\LocalUser;
|
||||||
@ -138,7 +139,7 @@ class Nickname
|
|||||||
* @throws NicknameTooLongException
|
* @throws NicknameTooLongException
|
||||||
* @throws NicknameTooShortException
|
* @throws NicknameTooShortException
|
||||||
*/
|
*/
|
||||||
public static function normalize(string $nickname, bool $check_already_used = true, bool $check_reserved = true): string
|
public static function normalize(string $nickname, bool $check_already_used = true, bool $checking_reserved = true): string
|
||||||
{
|
{
|
||||||
if (mb_strlen($nickname) > self::MAX_LEN) {
|
if (mb_strlen($nickname) > self::MAX_LEN) {
|
||||||
// Display forms must also fit!
|
// Display forms must also fit!
|
||||||
@ -151,18 +152,21 @@ class Nickname
|
|||||||
$nickname = mb_strtolower($nickname);
|
$nickname = mb_strtolower($nickname);
|
||||||
$nickname = Normalizer::normalize($nickname, Normalizer::FORM_C);
|
$nickname = Normalizer::normalize($nickname, Normalizer::FORM_C);
|
||||||
|
|
||||||
if (mb_strlen($original_nickname) < 1) {
|
if (!$checking_reserved) {
|
||||||
throw new NicknameEmptyException();
|
if (mb_strlen($original_nickname) < 1) {
|
||||||
} elseif (mb_strlen($original_nickname) < Common::config('nickname', 'min_length')) {
|
throw new NicknameEmptyException();
|
||||||
throw new NicknameTooShortException();
|
} elseif (mb_strlen($original_nickname) < Common::config('nickname', 'min_length')) {
|
||||||
} elseif (!self::isCanonical($original_nickname) && !filter_var($original_nickname, FILTER_VALIDATE_EMAIL)) {
|
Log::critical(var_dump($original_nickname, mb_strlen($original_nickname), Common::config('nickname', 'min_length'), mb_strlen($original_nickname) < Common::config('nickname', 'min_length')));
|
||||||
throw new NicknameInvalidException();
|
throw new NicknameTooShortException();
|
||||||
} elseif ($check_reserved && self::isReserved($original_nickname) || Common::isSystemPath($original_nickname)) {
|
} elseif (!self::isCanonical($original_nickname) && !filter_var($original_nickname, FILTER_VALIDATE_EMAIL)) {
|
||||||
throw new NicknameReservedException();
|
throw new NicknameInvalidException();
|
||||||
} elseif ($check_already_used) {
|
} elseif (self::isReserved($original_nickname) || Common::isSystemPath($original_nickname)) {
|
||||||
$actor = self::isTaken($original_nickname);
|
throw new NicknameReservedException();
|
||||||
if ($actor instanceof GSActor) {
|
} elseif ($check_already_used) {
|
||||||
throw new NicknameTakenException($actor);
|
$actor = self::isTaken($original_nickname);
|
||||||
|
if ($actor instanceof GSActor) {
|
||||||
|
throw new NicknameTakenException($actor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user