Skip to content

Commit ebfbf16

Browse files
committed
object normalizer caught up with upstream
1 parent 3002ec9 commit ebfbf16

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ protected function extractAttributes(object $object, ?string $format = null, arr
100100
$name = $reflMethod->name;
101101
$attributeName = null;
102102

103-
if (3 < \strlen($name) && match ($name[0]) {
103+
// ctype_lower check to find out if method looks like accessor but actually is not, e.g. hash, cancel
104+
if (3 < \strlen($name) && !ctype_lower($name[3]) && match ($name[0]) {
104105
'g' => str_starts_with($name, 'get'),
105106
'h' => str_starts_with($name, 'has'),
106107
'c' => str_starts_with($name, 'can'),
@@ -112,7 +113,7 @@ protected function extractAttributes(object $object, ?string $format = null, arr
112113
if (!$reflClass->hasProperty($attributeName)) {
113114
$attributeName = lcfirst($attributeName);
114115
}
115-
} elseif ('is' !== $name && str_starts_with($name, 'is')) {
116+
} elseif ('is' !== $name && str_starts_with($name, 'is') && !ctype_lower($name[2])) {
116117
// issers
117118
$attributeName = substr($name, 2);
118119

src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ public function testNormalizeWithMethodNamesSimilarToAccessors()
942942
'tell' => true,
943943
'class' => true,
944944
'responsibility' => true,
945+
123 => 321
945946
], $normalized);
946947
}
947948
}
@@ -1260,4 +1261,14 @@ public function hasResponsibility()
12601261
{
12611262
return true;
12621263
}
1264+
1265+
public function get_foo()
1266+
{
1267+
return 'bar';
1268+
}
1269+
1270+
public function get123()
1271+
{
1272+
return 321;
1273+
}
12631274
}

0 commit comments

Comments
 (0)