8000 bug #60888 [Intl] Fix locale validator when canonicalize is true (rda… · symfony/symfony@c6f3da1 · GitHub
[go: up one dir, main page]

Skip to content

Commit c6f3da1

Browse files
bug #60888 [Intl] Fix locale validator when canonicalize is true (rdavaillaud)
This PR was merged into the 6.4 branch. Discussion ---------- [Intl] Fix locale validator when canonicalize is true | Q | A | ------------- | --- | Branch? | 6.4,7.x | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT When canonicalize is set to true, and the value passed to the validator is not a valid locale, ext-intl Locale::canonicalize should return null. This is not the case with ICU <76, and this method returns an empty string. But with the latest ICU lib, this method really returns null. The problem is with `Locales::exists()` which only accept non null string. This commit handles the returned null value in the validator. Commits ------- fd5b24b [Intl] Fix locale validator when canonicalize is true
2 parents 1eae08e + fd5b24b commit c6f3da1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Symfony/Component/Validator/Constraints/LocaleValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function validate(mixed $value, Constraint $constraint)
4747
$value = \Locale::canonicalize($value);
4848
}
4949

50-
if (!Locales::exists($value)) {
50+
if (null === $value || !Locales::exists($value)) {
5151
$this->context->buildViolation($constraint->message)
5252
->setParameter('{{ value }}', $this->formatValue($inputValue))
5353
->setCode(Locale::NO_SUCH_LOCALE_ERROR)

src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ public static function getInvalidLocales()
9191
];
9292
}
9393

94+
public function testTooLongLocale()
95+
{
96+
$constraint = new Locale([
97+
'message' => 'myMessage',
98+
]);
99+
100+
$locale = str_repeat('a', (\defined('INTL_MAX_LOCALE_LEN') ? \INTL_MAX_LOCALE_LEN : 85) + 1);
101+
$this->validator->validate($locale, $constraint);
102+
103+
$this->buildViolation('myMessage')
104+
->setParameter('{{ value }}', '"' . $locale . '"')
105+
->setCode(Locale::NO_SUCH_LOCALE_ERROR)
106+
->assertRaised();
107+
}
108+
94109
/**
95110
* @dataProvider getUncanonicalizedLocales
96111
*/

0 commit comments

Comments
 (0)
0