8000 Merge branch '7.1' into 7.2 · symfony/symfony@e0ed5ee · GitHub
[go: up one dir, main page]

Skip to content

Commit e0ed5ee

Browse files
Merge branch '7.1' into 7.2
* 7.1: synchronize IBAN formats [PropertyAccess] Fix handling property names with a `.`
2 parents 4eac728 + 58ee0d3 commit e0ed5ee

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function getValue(object|array $objectOrArray, string|PropertyPathInterfa
9898
self::VALUE => $objectOrArray,
9999
];
100100

101-
if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[?')) {
101+
if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[?') || $objectOrArray instanceof \stdClass && property_exists($objectOrArray, $propertyPath))) {
102102
return $this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty)[self::VALUE];
103103
}
104104

@@ -111,7 +111,7 @@ public function getValue(object|array $objectOrArray, string|PropertyPathInterfa
111111

112112
public function setValue(object|array &$objectOrArray, string|PropertyPathInterface $propertyPath, mixed $value): void
113113
{
114-
if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[')) {
114+
if (\is_object($objectOrArray) && (false === strpbrk((string) $propertyPath, '.[') || $objectOrArray instanceof \stdClass && property_exists($objectOrArray, $propertyPath))) {
115115
$zval = [
116116
self::VALUE => $objectOrArray,
117117
];
@@ -214,7 +214,13 @@ public function isReadable(object|array $objectOrArray, string|PropertyPathInter
214214
$zval = [
215215
self::VALUE => $objectOrArray,
216216
];
217-
$this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices);
217+
218+
// handle stdClass with properties with a dot in the name
219+
if ($objectOrArray instanceof \stdClass && str_contains($propertyPath, '.') && property_exists($objectOrArray, $propertyPath)) {
220+
$this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty);
221+
} else {
222+
$this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices);
223+
}
218224

219225
return true;
220226
} catch (AccessException|UnexpectedTypeException) {
@@ -230,6 +236,14 @@ public function isWritable(object|array $objectOrArray, string|PropertyPathInter
230236
$zval = [
231237
self::VALUE => $objectOrArray,
232238
];
239+
240+
// handle stdClass with properties with a dot in the name
241+
if ($objectOrArray instanceof \stdClass && str_contains($propertyPath, '.') && property_exists($objectOrArray, $propertyPath)) {
242+
$this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty);
243+
244+
return true;
245+
}
246+
233247
$propertyValues = $this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength() - 1);
234248

235249
for ($i = \count($propertyValues) - 1; 0 <= $i; --$i) {

src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ public static function getValidWritePropertyPaths()
532532
[['firstName' => 'Bernhard'], '[firstName]', 'Bernhard'],
533533
[['index' => ['firstName' => 'Bernhard']], '[index][firstName]', 'Bernhard'],
534534
[(object) ['firstName' => 'Bernhard'], 'firstName', 'Bernhard'],
535+
[(object) ['first.Name' => 'Bernhard'], 'first.Name', 'Bernhard'],
535536
[(object) ['property' => ['firstName' => 'Bernhard']], 'property[firstName]', 'Bernhard'],
536537
[['index' => (object) ['firstName' => 'Bernhard']], '[index].firstName', 'Bernhard'],
537538
[(object) ['property' => (object) ['firstName' => 'Bernhard']], 'property.firstName', 'Bernhard'],

src/Symfony/Component/Validator/Constraints/IbanValidator.php

Lines changed: 4 additions & 0 deletions
6D40
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class IbanValidator extends ConstraintValidator
7373
'EG' => 'EG\d{2}\d{4}\d{4}\d{17}', // Egypt
7474
'ES' => 'ES\d{2}\d{4}\d{4}\d{1}\d{1}\d{10}', // Spain
7575
'FI' => 'FI\d{2}\d{3}\d{11}', // Finland
76+
'FK' => 'FK\d{2}[A-Z]{2}\d{12}', // Falkland Islands
7677
'FO' => 'FO\d{2}\d{4}\d{9}\d{1}', // Faroe Islands
7778
'FR' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France
7879
'GA' => 'GA\d{2}\d{23}', // Gabon
@@ -117,6 +118,7 @@ class IbanValidator extends ConstraintValidator
117118
'MG' => 'MG\d{2}\d{23}', // Madagascar
118119
'MK' => 'MK\d{2}\d{3}[\dA-Z]{10}\d{2}', // Macedonia
119120
'ML' => 'ML\d{2}[\dA-Z]{2}\d{22}', // Mali
121+
'MN' => 'MN\d{2}\d{4}\d{12}', // Mongolia
120122
'MQ' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France
121123
'MR' => 'MR\d{2}\d{5}\d{5}\d{11}\d{2}', // Mauritania
122124
'MT' => 'MT\d{2}[A-Z]{4}\d{5}[\dA-Z]{18}', // Malta
@@ -127,6 +129,7 @@ class IbanValidator extends ConstraintValidator
127129
'NI' => 'NI\d{2}[A-Z]{4}\d{24}', // Nicaragua
128130
'NL' => 'NL\d{2}[A-Z]{4}\d{10}', // Netherlands (The)
129131
'NO' => 'NO\d{2}\d{4}\d{6}\d{1}', // Norway
132+
'OM' => 'OM\d{2}\d{3}[\dA-Z]{16}', // Oman
130133
'PF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France
131134
'PK' => 'PK\d{2}[A-Z]{4}[\dA-Z]{16}', // Pakistan
132135
'PL' => 'PL\d{2}\d{8}\d{16}', // Poland
@@ -160,6 +163,7 @@ class IbanValidator extends ConstraintValidator
160163
'VG' => 'VG\d{2}[A-Z]{4}\d{16}', // Virgin Islands
161164
'WF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France
162165
'XK' => 'XK\d{2}\d{4}\d{10}\d{2}', // Kosovo
166+
'YE' => 'YE\d{2}[A-Z]{4}\d{4}[\dA-Z]{18}', // Yemen
163167
'YT' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France
164168
];
165169

src/Symfony/Component/Validator/Resources/bin/sync-iban-formats.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function getIbanFormats(): array
168168
$formats = [];
169169

170170
foreach ($this->readIbanFormatsTable() as $item) {
171-
if (!preg_match('/^([A-Z]{2})/', $item['Example'], $matches)) {
171+
if (!preg_match('/^([A-Z]{2})/', $item['IBAN Fields'], $matches)) {
172172
continue;
173173
}
174174

src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public static function getValidIbans()
8787
['CZ65 0800 0000 1920 0014 5399'], // Czech Republic
8888
['DK50 0040 0440 1162 43'], // Denmark
8989
['EE38 2200 2210 2014 5685'], // Estonia
90+
['FK12 SC98 7654 3210 98'], // Falkland Islands
9091
['FO97 5432 0388 8999 44'], // Faroe Islands
9192
['FI21 1234 5600 0007 85'], // Finland
9293
['FR14 2004 1010 0505 0001 3M02 606'], // France
@@ -112,9 +113,11 @@ public static function getValidIbans()
112113
['MU17 BOMM 0101 1010 3030 0200 000M UR'], // Mauritius
113114
['MD24 AG00 0225 1000 1310 4168'], // Moldova
114115
['MC93 2005 2222 1001 1223 3M44 555'], // Monaco
116+
['MN14 0005 0051 6384 7716'], // Mongolia
115117
['ME25 5050 0001 2345 6789 51'], // Montenegro
116118
['NL39 RABO 0300 0652 64'], // Netherlands
117119
['NO93 8601 1117 947'], // Norway
120+
['OM04 0280 0000 1234 5678 901'], // Oman
118121
['PK36 SCBL 0000 0011 2345 6702'], // Pakistan
119122
['PL60 1020 1026 0000 0422 7020 1111'], // Poland
120123
['PT50 0002 0123 1234 5678 9015 4'], // Portugal
@@ -131,6 +134,7 @@ public static function getValidIbans()
131134
['TR33 0006 1005 1978 6457 8413 26'], // Turkey
132135
['AE07 0331 2345 6789 0123 456'], // UAE
133136
['GB12 CPBK 0892 9965 0449 91'], // United Kingdom
137+
['YE09 CBKU 0000 0000 0000 1234 5601 01'], // Yemen
134138

135139
['DJ21 0001 0000 0001 5400 0100 186'], // Djibouti
136140
['EG38 0019 0005 0000 0000 2631 8000 2'], // Egypt

0 commit comments

Comments
 (0)
0