10000 [Validator] Add `{{pattern}}` to `Regex` constraint violations by alamirault · Pull Request #48232 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Add {{pattern}} to Regex constraint violations #48232

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

Merged
merged 1 commit into from
Dec 9, 2022
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
[Validator] Add pattern in Regex constraint violations
  • Loading branch information
alamirault authored and fabpot committed Dec 9, 2022
commit 369b051e28f12e29212da8ea77ddb8bd6ed0f118
1 change: 1 addition & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

* Add `Uuid::TIME_BASED_VERSIONS` to match that a UUID being validated embeds a timestamp
* Add the `pattern` parameter in violations of the `Regex` constraint

6.2
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function validate(mixed $value, Constraint $constraint)
if ($constraint->match xor preg_match($constraint->pattern, $value)) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setParameter('{{ pattern }}', $constraint->pattern)
->setCode(Regex::REGEX_FAILED_ERROR)
->addViolation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function testInvalidValues($value)

$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"'.$value.'"')
->setParameter('{{ pattern }}', '/^[0-9]+$/')
->setCode(Regex::REGEX_FAILED_ERROR)
->assertRaised();
}
Expand All @@ -133,6 +134,7 @@ public function testInvalidValuesNamed($value)

$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"'.$value.'"')
->setParameter('{{ pattern }}', '/^[0-9]+$/')
->setCode(Regex::REGEX_FAILED_ERROR)
->assertRaised();
}
Expand Down
0