Skip to content
Merged
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
6 changes: 3 additions & 3 deletions lib/Assert/Assertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ public static function url($value, $message = null, ?string $propertyPath = null
(?:/ (?:[\pL\pN\-._\~!$&\'()*+,;=:@]|%%[0-9A-Fa-f]{2})* )* # a path
(?:\? (?:[\pL\pN\-._\~!$&\'\[\]()*+,;=:@/?]|%%[0-9A-Fa-f]{2})* )? # a query (optional)
(?:\# (?:[\pL\pN\-._\~!$&\'()*+,;=:@/?]|%%[0-9A-Fa-f]{2})* )? # a fragment (optional)
$~ixu';
$~ixuD';

$pattern = \sprintf($pattern, \implode('|', $protocols));

Expand All @@ -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-Z]{1}[a-zA-Z0-9]*)$)D', $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 Expand Up @@ -2004,7 +2004,7 @@ public static function uuid($value, $message = null, ?string $propertyPath = nul
*/
public static function e164($value, $message = null, ?string $propertyPath = null): bool
{
if (!\preg_match('/^\+?[1-9]\d{1,14}$/', $value)) {
if (!\preg_match('/^\+?[1-9]\d{1,14}$/D', $value)) {
$message = \sprintf(
static::generateMessage($message ?: 'Value "%s" is not a valid E164.'),
static::stringify($value)
Expand Down
9 changes: 9 additions & 0 deletions tests/Assert/Tests/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ public function dataInvalidUrl(): array
['http://:password@@symfony.com'],
['http://username:passwordsymfony.com'],
['http://usern@me:password@symfony.com'],
["http://www.google.com\n"],
];
}

Expand Down Expand Up @@ -898,6 +899,13 @@ public function testInvalidAlnum()
Assertion::alnum('1a');
}

public function testInvalidAlnumWithTrailingNewline()
{
$this->expectException('Assert\AssertionFailedException');
$this->expectExceptionCode(\Assert\Assertion::INVALID_ALNUM);
Assertion::alnum("a1b2c3\n");
}

public function testValidTrue()
{
$this->assertTrue(Assertion::true(1 == 1));
Expand Down Expand Up @@ -1306,6 +1314,7 @@ public function providesInvalidE164s(): array
return [
['+3362652569e'],
['+3361231231232652569'],
["+33626525690\n"],
];
}

Expand Down
Loading