From fd5b24b95aa46d879616e73abff45f58afd7577d Mon Sep 17 00:00:00 2001 From: Raphael Davaillaud Date: Tue, 24 Jun 2025 12:11:17 +0200 Subject: [PATCH] [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 --- .../Validator/Constraints/LocaleValidator.php | 2 +- .../Tests/Constraints/LocaleValidatorTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php index 4cd0b120b4f67..11045ca95f60e 100644 --- a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php @@ -47,7 +47,7 @@ public function validate(mixed $value, Constraint $constraint) $value = \Locale::canonicalize($value); } - if (!Locales::exists($value)) { + if (null === $value || !Locales::exists($value)) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($inputValue)) ->setCode(Locale::NO_SUCH_LOCALE_ERROR) diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php index 4eec91c63d683..fe3594eb47740 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php @@ -91,6 +91,21 @@ public static function getInvalidLocales() ]; } + public function testTooLongLocale() + { + $constraint = new Locale([ + 'message' => 'myMessage', + ]); + + $locale = str_repeat('a', (\defined('INTL_MAX_LOCALE_LEN') ? \INTL_MAX_LOCALE_LEN : 85) + 1); + $this->validator->validate($locale, $constraint); + + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"' . $locale . '"') + ->setCode(Locale::NO_SUCH_LOCALE_ERROR) + ->assertRaised(); + } + /** * @dataProvider getUncanonicalizedLocales */ 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