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
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/Slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Slug extends Constraint
public const NOT_SLUG_ERROR = '14e6df1e-c8ab-4395-b6ce-04b132a3765e';

public string $message = 'This value is not a valid slug.';
public string $regex = '/^[a-z0-9]+(?:-[a-z0-9]+)*$/';
public string $regex = '/^[a-z0-9]+(?:-[a-z0-9]+)*$/i';

#[HasNamedArguments]
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Validator\Tests\Constraints;

use Symfony\Component\String\Slugger\AsciiSlugger;
use Symfony\Component\Validator\Constraints\Slug;
use Symfony\Component\Validator\Constraints\SlugValidator;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
Expand Down Expand Up @@ -47,6 +48,7 @@ public function testExpectsStringCompatibleType()
* @testWith ["test-slug"]
* ["slug-123-test"]
* ["slug"]
* ["TestSlug"]
*/
public function testValidSlugs($slug)
{
Expand All @@ -56,8 +58,7 @@ public function testValidSlugs($slug)
}

/**
* @testWith ["NotASlug"]
* ["Not a slug"]
* @testWith ["Not a slug"]
* ["not-á-slug"]
* ["not-@-slug"]
*/
Expand Down Expand Up @@ -91,7 +92,7 @@ public function testCustomRegexInvalidSlugs($slug)

/**
* @testWith ["slug"]
* @testWith ["test1234"]
* ["test1234"]
*/
public function testCustomRegexValidSlugs($slug)
{
Expand All @@ -101,4 +102,16 @@ public function testCustomRegexValidSlugs($slug)

$this->assertNoViolation();
}

/**
* @testWith ["PHP"]
* ["Symfony is cool"]
* ["Lorem ipsum dolor sit amet"]
*/
public function testAcceptAsciiSluggerResults(string $text)
{
$this->validator->validate((new AsciiSlugger())->slug($text), new Slug());

$this->assertNoViolation();
}
}
1 change: 1 addition & 0 deletions src/Symfony/Component/Validator/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"symfony/mime": "^6.4|^7.0",
"symfony/property-access": "^6.4|^7.0",
"symfony/property-info": "^6.4|^7.0",
"symfony/string": "^6.4|^7.0",
"symfony/translation": "^6.4.3|^7.0.3",
"symfony/type-info": "^7.1",
"egulias/email-validator": "^2.1.10|^3|^4"
Expand Down
Loading