Skip to content

Commit 7112882

Browse files
committed
Merge remote-tracking branch 'city/39854-fix-city-name-validation' into AC-14495
2 parents 2a1e1e5 + 622621e commit 7112882

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ class City extends AbstractValidator
2020
*
2121
* \p{L}: Unicode letters.
2222
* \p{M}: Unicode marks (diacritic marks, accents, etc.).
23-
* ': Apostrophe mark.
23+
* \d: Digits (0-9).
2424
* \s: Whitespace characters (spaces, tabs, newlines, etc.).
25+
* -: Hyphen.
26+
* _: Underscore.
27+
* ', ’: Apostrophes (straight and typographical).
28+
* .: Period/full stop.
29+
* ,: Comma.
30+
* &: Ampersand.
31+
* (): Parentheses.
2532
*/
26-
private const PATTERN_CITY = '/(?:[\p{L}\p{M}\s\-\']{1,100})/u';
33+
private const PATTERN_CITY = '/^[\p{L}\p{M}\d\s\-_\'’\.,&\(\)]{1,100}$/u';
2734

2835
/**
2936
* Validate city fields.
@@ -35,7 +42,7 @@ public function isValid($customer)
3542
{
3643
if (!$this->isValidCity($customer->getCity())) {
3744
parent::_addMessages([[
38-
'city' => "Invalid City. Please use A-Z, a-z, 0-9, -, ', spaces"
45+
'city' => "Invalid City. Please use letters, numbers, spaces, and the following characters: - _ ' ’ . , & ( )"
3946
]]);
4047
}
4148

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)