diff --git a/src/Symfony/Component/Validator/Constraints/Slug.php b/src/Symfony/Component/Validator/Constraints/Slug.php index 52a5d94c2d93b..55d847ccb618b 100644 --- a/src/Symfony/Component/Validator/Constraints/Slug.php +++ b/src/Symfony/Component/Validator/Constraints/Slug.php @@ -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( diff --git a/src/Symfony/Component/Validator/Tests/Constraints/SlugValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/SlugValidatorTest.php index e8d210b8377e3..f88bff3e167ef 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/SlugValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/SlugValidatorTest.php @@ -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; @@ -47,6 +48,7 @@ public function testExpectsStringCompatibleType() * @testWith ["test-slug"] * ["slug-123-test"] * ["slug"] + * ["TestSlug"] */ public function testValidSlugs($slug) { @@ -56,8 +58,7 @@ public function testValidSlugs($slug) } /** - * @testWith ["NotASlug"] - * ["Not a slug"] + * @testWith ["Not a slug"] * ["not-รก-slug"] * ["not-@-slug"] */ @@ -91,7 +92,7 @@ public function testCustomRegexInvalidSlugs($slug) /** * @testWith ["slug"] - * @testWith ["test1234"] + * ["test1234"] */ public function testCustomRegexValidSlugs($slug) { @@ -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(); + } } diff --git a/src/Symfony/Component/Validator/composer.json b/src/Symfony/Component/Validator/composer.json index 5177d37d2955a..0eaac5f6bf735 100644 --- a/src/Symfony/Component/Validator/composer.json +++ b/src/Symfony/Component/Validator/composer.json @@ -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"