Skip to content

Commit a2bd44d

Browse files
committed
Merge remote-tracking branch 'origin/AC-14495' into spartans_pr_04082025
2 parents 3b253bc + c2757ef commit a2bd44d

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe.
4+
* All rights reserved.
55
*/
66
declare(strict_types=1);
77

@@ -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,8 @@ 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,
46+
and the following characters: - _ ' ’ . , & ( )"
3947
]]);
4048
}
4149

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe.
4+
* All rights reserved.
55
*/
66
declare(strict_types=1);
77

@@ -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)