Loading src/Plugin/Validation/Constraint/UsernameFormatConstraint.php +29 −0 Original line number Diff line number Diff line Loading @@ -14,10 +14,39 @@ use Symfony\Component\Validator\Constraint; */ class UsernameFormatConstraint extends Constraint { /** * Violation message when the username begins with a space. * * @var string */ public $spaceBeginMessage = 'The username cannot begin with a space.'; /** * Violation message when the username ends with a space. * * @var string */ public $spaceEndMessage = 'The username cannot end with a space.'; /** * Violation message when the username contains multiple spaces in a row. * * @var string */ public $multipleSpacesMessage = 'The username cannot contain multiple spaces in a row.'; /** * Violation message when the username contains an illegal character. * * @var string */ public $illegalMessage = 'The username contains an illegal character.'; /** * Violation message when the username exceeds its maximum character limit. * * @var string */ public $tooLongMessage = 'The username %name is too long: it must be %max characters or less.'; } src/Plugin/Validation/Constraint/UsernameFormatConstraintValidator.php +9 −9 Original line number Diff line number Diff line Loading @@ -29,23 +29,23 @@ class UsernameFormatConstraintValidator extends ConstraintValidator { } if (preg_match('/[^\x{80}-\x{F7} a-z0-9@+_.\'-]/i', $name) || preg_match( // Non-printable ISO-8859-1 + NBSP // Non-printable ISO-8859-1 + NBSP. '/[\x{80}-\x{A0}' . // Soft-hyphen // Soft-hyphen. '\x{AD}' . // Various space characters // Various space characters. '\x{2000}-\x{200F}' . // Bidirectional text overrides // Bidirectional text overrides. '\x{2028}-\x{202F}' . // Various text hinting characters // Various text hinting characters. '\x{205F}-\x{206F}' . // Byte order mark // Byte order mark. '\x{FEFF}' . // Full-width latin // Full-width latin. '\x{FF01}-\x{FF60}' . // Replacement characters // Replacement characters. '\x{FFF9}-\x{FFFD}' . // NULL byte and control characters // NULL byte and control characters. '\x{0}-\x{1F}]/u', $name) ) { Loading tests/src/Kernel/ConfigTest.php +3 −1 Original line number Diff line number Diff line Loading @@ -5,12 +5,14 @@ namespace Drupal\Tests\do_username\Kernel; use Drupal\KernelTests\KernelTestBase; /** * Tests that the Drupal.org Username module config installs correctly. * * @group do_username */ class ConfigTest extends KernelTestBase { /** * Modules to enable * Modules to enable. * * @var array */ Loading Loading
src/Plugin/Validation/Constraint/UsernameFormatConstraint.php +29 −0 Original line number Diff line number Diff line Loading @@ -14,10 +14,39 @@ use Symfony\Component\Validator\Constraint; */ class UsernameFormatConstraint extends Constraint { /** * Violation message when the username begins with a space. * * @var string */ public $spaceBeginMessage = 'The username cannot begin with a space.'; /** * Violation message when the username ends with a space. * * @var string */ public $spaceEndMessage = 'The username cannot end with a space.'; /** * Violation message when the username contains multiple spaces in a row. * * @var string */ public $multipleSpacesMessage = 'The username cannot contain multiple spaces in a row.'; /** * Violation message when the username contains an illegal character. * * @var string */ public $illegalMessage = 'The username contains an illegal character.'; /** * Violation message when the username exceeds its maximum character limit. * * @var string */ public $tooLongMessage = 'The username %name is too long: it must be %max characters or less.'; }
src/Plugin/Validation/Constraint/UsernameFormatConstraintValidator.php +9 −9 Original line number Diff line number Diff line Loading @@ -29,23 +29,23 @@ class UsernameFormatConstraintValidator extends ConstraintValidator { } if (preg_match('/[^\x{80}-\x{F7} a-z0-9@+_.\'-]/i', $name) || preg_match( // Non-printable ISO-8859-1 + NBSP // Non-printable ISO-8859-1 + NBSP. '/[\x{80}-\x{A0}' . // Soft-hyphen // Soft-hyphen. '\x{AD}' . // Various space characters // Various space characters. '\x{2000}-\x{200F}' . // Bidirectional text overrides // Bidirectional text overrides. '\x{2028}-\x{202F}' . // Various text hinting characters // Various text hinting characters. '\x{205F}-\x{206F}' . // Byte order mark // Byte order mark. '\x{FEFF}' . // Full-width latin // Full-width latin. '\x{FF01}-\x{FF60}' . // Replacement characters // Replacement characters. '\x{FFF9}-\x{FFFD}' . // NULL byte and control characters // NULL byte and control characters. '\x{0}-\x{1F}]/u', $name) ) { Loading
tests/src/Kernel/ConfigTest.php +3 −1 Original line number Diff line number Diff line Loading @@ -5,12 +5,14 @@ namespace Drupal\Tests\do_username\Kernel; use Drupal\KernelTests\KernelTestBase; /** * Tests that the Drupal.org Username module config installs correctly. * * @group do_username */ class ConfigTest extends KernelTestBase { /** * Modules to enable * Modules to enable. * * @var array */ Loading