Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix alnum() assertion only allowed strings that started with a character #314

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Assert/Assertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'),
Expand Down
3 changes: 2 additions & 1 deletion tests/Assert/Tests/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down