Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d51f563

Browse filesBrowse files
committed
let the SlugValidator accept AsciiSlugger results
1 parent 170b631 commit d51f563
Copy full SHA for d51f563

File tree

3 files changed

+18
-4
lines changed
Filter options

3 files changed

+18
-4
lines changed

‎src/Symfony/Component/Validator/Constraints/Slug.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Slug.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Slug extends Constraint
2525
public const NOT_SLUG_ERROR = '14e6df1e-c8ab-4395-b6ce-04b132a3765e';
2626

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

3030
#[HasNamedArguments]
3131
public function __construct(

‎src/Symfony/Component/Validator/Tests/Constraints/SlugValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/SlugValidatorTest.php
+16-3Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

14+
use Symfony\Component\String\Slugger\AsciiSlugger;
1415
use Symfony\Component\Validator\Constraints\Slug;
1516
use Symfony\Component\Validator\Constraints\SlugValidator;
1617
use Symfony\Component\Validator\Exception\UnexpectedValueException;
@@ -47,6 +48,7 @@ public function testExpectsStringCompatibleType()
4748
* @testWith ["test-slug"]
4849
* ["slug-123-test"]
4950
* ["slug"]
51+
* ["TestSlug"]
5052
*/
5153
public function testValidSlugs($slug)
5254
{
@@ -56,8 +58,7 @@ public function testValidSlugs($slug)
5658
}
5759

5860
/**
59-
* @testWith ["NotASlug"]
60-
* ["Not a slug"]
61+
* @testWith ["Not a slug"]
6162
* ["not-á-slug"]
6263
* ["not-@-slug"]
6364
*/
@@ -91,7 +92,7 @@ public function testCustomRegexInvalidSlugs($slug)
9192

9293
/**
9394
* @testWith ["slug"]
94-
* @testWith ["test1234"]
95+
* ["test1234"]
9596
*/
9697
public function testCustomRegexValidSlugs($slug)
9798
{
@@ -101,4 +102,16 @@ public function testCustomRegexValidSlugs($slug)
101102

102103
$this->assertNoViolation();
103104
}
105+
106+
/**
107+
* @testWith ["PHP"]
108+
* ["Symfony is cool"]
109+
* ["Lorem ipsum dolor sit amet"]
110+
*/
111+
public function testAcceptAsciiSluggerResults(string $text)
112+
{
113+
$this->validator->validate((new AsciiSlugger())->slug($text), new Slug());
114+
115+
$this->assertNoViolation();
116+
}
104117
}

‎src/Symfony/Component/Validator/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/composer.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"symfony/mime": "^6.4|^7.0",
3939
"symfony/property-access": "^6.4|^7.0",
4040
"symfony/property-info": "^6.4|^7.0",
41+
"symfony/string": "^6.4|^7.0",
4142
"symfony/translation": "^6.4.3|^7.0.3",
4243
"symfony/type-info": "^7.1",
4344
"egulias/email-validator": "^2.1.10|^3|^4"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.