From e1a05566ebd14cca2b038d24299d1a1964058742 Mon Sep 17 00:00:00 2001 From: Bhushan Kashyap Date: Thu, 24 Apr 2025 16:35:35 +0530 Subject: [PATCH 1/3] 39854: Fix city name validation to allow digits, &, ., () characters --- app/code/Magento/Customer/Model/Validator/City.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/City.php b/app/code/Magento/Customer/Model/Validator/City.php index 0b53551dfd88f..713ae8365bf29 100644 --- a/app/code/Magento/Customer/Model/Validator/City.php +++ b/app/code/Magento/Customer/Model/Validator/City.php @@ -20,10 +20,16 @@ class City extends AbstractValidator * * \p{L}: Unicode letters. * \p{M}: Unicode marks (diacritic marks, accents, etc.). - * ': Apostrophe mark. + * \d: Digits (0-9). * \s: Whitespace characters (spaces, tabs, newlines, etc.). + * -: Hyphen. + * ': Apostrophe mark. + * .: Period/full stop. + * ,: Comma. + * &: Ampersand. + * (): Parentheses. */ - private const PATTERN_CITY = '/(?:[\p{L}\p{M}\s\-\']{1,100})/u'; + private const PATTERN_CITY = '/^[\p{L}\p{M}\d\s\-\'\.,&\(\)]{1,100}$/u'; /** * Validate city fields. From 74e6c1dc9116df851c6c1700ee18f5d3ac25da49 Mon Sep 17 00:00:00 2001 From: Bhushan Kashyap Date: Fri, 25 Apr 2025 15:03:04 +0530 Subject: [PATCH 2/3] 39854: Update city validation error message to match allowed characters --- app/code/Magento/Customer/Model/Validator/City.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Validator/City.php b/app/code/Magento/Customer/Model/Validator/City.php index 713ae8365bf29..3ee2a6ac7563f 100644 --- a/app/code/Magento/Customer/Model/Validator/City.php +++ b/app/code/Magento/Customer/Model/Validator/City.php @@ -41,7 +41,7 @@ public function isValid($customer) { if (!$this->isValidCity($customer->getCity())) { parent::_addMessages([[ - 'city' => "Invalid City. Please use A-Z, a-z, 0-9, -, ', spaces" + 'city' => "Invalid City. Please use letters, numbers, spaces, and the following characters: - ' . , & ( )" ]]); } From 0380a6b8580a6358cd96140373033d931a6a4c9f Mon Sep 17 00:00:00 2001 From: Bhushan Kashyap Date: Sat, 26 Apr 2025 01:31:06 +0530 Subject: [PATCH 3/3] 39854: Add support for typographical apostrophe and underscore in city validation and update test cases --- .../Magento/Customer/Model/Validator/City.php | 7 ++-- .../Test/Unit/Model/Validator/CityTest.php | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/City.php b/app/code/Magento/Customer/Model/Validator/City.php index 3ee2a6ac7563f..724ffe8d645a5 100644 --- a/app/code/Magento/Customer/Model/Validator/City.php +++ b/app/code/Magento/Customer/Model/Validator/City.php @@ -23,13 +23,14 @@ class City extends AbstractValidator * \d: Digits (0-9). * \s: Whitespace characters (spaces, tabs, newlines, etc.). * -: Hyphen. - * ': Apostrophe mark. + * _: Underscore. + * ', ’: Apostrophes (straight and typographical). * .: Period/full stop. * ,: Comma. * &: Ampersand. * (): Parentheses. */ - private const PATTERN_CITY = '/^[\p{L}\p{M}\d\s\-\'\.,&\(\)]{1,100}$/u'; + private const PATTERN_CITY = '/^[\p{L}\p{M}\d\s\-_\'’\.,&\(\)]{1,100}$/u'; /** * Validate city fields. @@ -41,7 +42,7 @@ public function isValid($customer) { if (!$this->isValidCity($customer->getCity())) { parent::_addMessages([[ - 'city' => "Invalid City. Please use letters, numbers, spaces, and the following characters: - ' . , & ( )" + 'city' => "Invalid City. Please use letters, numbers, spaces, and the following characters: - _ ' ’ . , & ( )" ]]); } diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php index af46e7f5c7748..bc68711d34d3a 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php @@ -79,6 +79,38 @@ public static function expectedPunctuationInNamesDataProvider(): array [ 'city' => ' Moscow Moscow', 'message' => 'Whitespace characters must be allowed in city' + ], + [ + 'city' => 'O\'Higgins', + 'message' => 'Straight apostrophe must be allowed in city names' + ], + [ + 'city' => 'O’Higgins', + 'message' => 'Typographical apostrophe must be allowed in city names' + ], + [ + 'city' => 'Saint_Petersburg', + 'message' => 'Underscore must be allowed in city names' + ], + [ + 'city' => 'Stratford-upon-Avon', + 'message' => 'Hyphens must be allowed in city names' + ], + [ + 'city' => 'St. Petersburg', + 'message' => 'Periods must be allowed in city names' + ], + [ + 'city' => 'Trinidad & Tobago', + 'message' => 'Ampersand must be allowed in city names' + ], + [ + 'city' => 'Winston-Salem (NC)', + 'message' => 'Parentheses must be allowed in city names' + ], + [ + 'city' => 'Rostov-on-Don, Russia', + 'message' => 'Commas must be allowed in city names' ] ]; }