Skip to content

Commit 0380a6b

Browse files
committed
39854: Add support for typographical apostrophe and underscore in city validation and update test cases
1 parent 74e6c1d commit 0380a6b

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

app/code/Magento/Customer/Model/Validator/City.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ class City extends AbstractValidator
2323
* \d: Digits (0-9).
2424
* \s: Whitespace characters (spaces, tabs, newlines, etc.).
2525
* -: Hyphen.
26-
* ': Apostrophe mark.
26+
* _: Underscore.
27+
* ', ’: Apostrophes (straight and typographical).
2728
* .: Period/full stop.
2829
* ,: Comma.
2930
* &: Ampersand.
3031
* (): Parentheses.
3132
*/
32-
private const PATTERN_CITY = '/^[\p{L}\p{M}\d\s\-\'\.,&\(\)]{1,100}$/u';
33+
private const PATTERN_CITY = '/^[\p{L}\p{M}\d\s\-_\'\.,&\(\)]{1,100}$/u';
3334

3435
/**
3536
* Validate city fields.
@@ -41,7 +42,7 @@ public function isValid($customer)
4142
{
4243
if (!$this->isValidCity($customer->getCity())) {
4344
parent::_addMessages([[
44-
'city' => "Invalid City. Please use letters, numbers, spaces, and the following characters: - ' . , & ( )"
45+
'city' => "Invalid City. Please use letters, numbers, spaces, and the following characters: - _ ' ’ . , & ( )"
4546
]]);
4647
}
4748

app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,38 @@ public static function expectedPunctuationInNamesDataProvider(): array
7979
[
8080
'city' => ' Moscow Moscow',
8181
'message' => 'Whitespace characters must be allowed in city'
82+
],
83+
[
84+
'city' => 'O\'Higgins',
85+
'message' => 'Straight apostrophe must be allowed in city names'
86+
],
87+
[
88+
'city' => 'O’Higgins',
89+
'message' => 'Typographical apostrophe must be allowed in city names'
90+
],
91+
[
92+
'city' => 'Saint_Petersburg',
93+
'message' => 'Underscore must be allowed in city names'
94+
],
95+
[
96+
'city' => 'Stratford-upon-Avon',
97+
'message' => 'Hyphens must be allowed in city names'
98+
],
99+
[
100+
'city' => 'St. Petersburg',
101+
'message' => 'Periods must be allowed in city names'
102+
],
103+
[
104+
'city' => 'Trinidad & Tobago',
105+
'message' => 'Ampersand must be allowed in city names'
106+
],
107+
[
108+
'city' => 'Winston-Salem (NC)',
109+
'message' => 'Parentheses must be allowed in city names'
110+
],
111+
[
112+
'city' => 'Rostov-on-Don, Russia',
113+
'message' => 'Commas must be allowed in city names'
82114
]
83115
];
84116
}

0 commit comments

Comments
 (0)