From b7b8ae80581cc6d65434b54c2da71c3f1d99d9e1 Mon Sep 17 00:00:00 2001 From: Victor Steblina Date: Tue, 16 Mar 2021 12:20:10 +0200 Subject: [PATCH] Fix alnum() assertion only allowed strings that started with a character --- lib/Assert/Assertion.php | 2 +- tests/Assert/Tests/AssertTest.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Assert/Assertion.php b/lib/Assert/Assertion.php index a91aa8e..6c2bb7b 100644 --- a/lib/Assert/Assertion.php +++ b/lib/Assert/Assertion.php @@ -1775,7 +1775,7 @@ public static function url($value, $message = null, string $propertyPath = null) public static function alnum($value, $message = null, string $propertyPath = null): bool { try { - static::regex($value, '(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $propertyPath); + static::regex($value, '(^([a-zA-Z0-9]*)$)', $message, $propertyPath); } catch (Throwable $e) { $message = \sprintf( static::generateMessage($message ?: 'Value "%s" is not alphanumeric, starting with letters and containing only letters and numbers.'), diff --git a/tests/Assert/Tests/AssertTest.php b/tests/Assert/Tests/AssertTest.php index 21eab65..a86394e 100644 --- a/tests/Assert/Tests/AssertTest.php +++ b/tests/Assert/Tests/AssertTest.php @@ -849,13 +849,14 @@ public function testValidAlnum() $this->assertTrue(Assertion::alnum('a1')); $this->assertTrue(Assertion::alnum('aasdf1234')); $this->assertTrue(Assertion::alnum('a1b2c3')); + $this->assertTrue(Assertion::alnum('1234567890')); } public function testInvalidAlnum() { $this->expectException('Assert\AssertionFailedException'); $this->expectExceptionCode(\Assert\Assertion::INVALID_ALNUM); - Assertion::alnum('1a'); + Assertion::alnum('_1a'); } public function testValidTrue()