fix player name rule

This commit is contained in:
Pig Fang 2021-08-22 16:45:26 +08:00
parent 2c579a4043
commit 3f7ba49c2c
No known key found for this signature in database
GPG Key ID: A8198F548DADA9E2
3 changed files with 20 additions and 2 deletions

View File

@ -22,7 +22,7 @@ class PlayerName implements Rule
break;
case 'utf8':
return mb_check_encoding($value, 'UTF-8');
return mb_check_encoding($value, 'UTF-8') && !preg_match('/\s/', $value);
case 'custom':
$regexp = option('custom_player_name_regexp') ?: $regexp;

View File

@ -115,7 +115,7 @@ general:
title: Player Name Rule
official: Letters, numbers and underscores (Mojang's official rule)
cjk: Allow CJK Unified Ideographs
utf8: Allow all valid UTF-8 characters
utf8: Allow all valid UTF-8 characters (excluding whitespaces)
custom: Use custom rules (regular expression)
custom_player_name_regexp:
title: Custom Player Name Rules

View File

@ -43,6 +43,24 @@ class PlayerNameTest extends TestCase
);
}
public function testUtf8()
{
option(['player_name_rule' => 'utf8']);
$rule = new PlayerName();
$this->assertTrue($rule->passes('', '_name_'));
$this->assertTrue($rule->passes('', 'NaN'));
$this->assertTrue($rule->passes('', '中文'));
$this->assertTrue($rule->passes('', '§Me'));
$this->assertTrue($rule->passes('', ';'));
$this->assertTrue($rule->passes('', '\\'));
$this->assertFalse($rule->passes('', 'a b'));
$this->assertFalse($rule->passes('', "a\n b"));
$this->assertFalse($rule->passes('', "a\tb"));
$this->assertFalse($rule->passes('', "a\fb"));
}
public function testCustom()
{
option(['player_name_rule' => 'custom']);