Skip to content

Commit fd5b24b

Browse files
rdavaillaudnicolas-grekas
authored andcommitted
[Intl] Fix locale validator when canonicalize is true
When canonicalize is set to true, and the value length exceeds INTL_MAX_LOCALE_LEN the validator throws an exception. The Intl Locale::canonicalize() method returns null when the value is too long and Locales::exists() only accept non null string. This commit allows to handle the null value as it should. [Intl] windows / php 8.1 INTL_MAX_LOCALE_LEN
1 parent 2da9a7d commit fd5b24b

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy