8000 bug #47255 [Serializer] Fix get accessor regex in AnnotationLoader (j… · enumag/symfony@1055404 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1055404

Browse files
committed
bug symfony#47255 [Serializer] Fix get accessor regex in AnnotationLoader (jsor)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Serializer] Fix get accessor regex in AnnotationLoader The pipe in the regex makes it match *all* methods. | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | n/a | License | MIT | Doc PR | n/a This fixes a bug introduced in symfony#46958. It was also discovered in the PR but after it got merged. See symfony#46958 (comment). Commits ------- 1132171 [Serializer] Fix get accessor regex in AnnotationLoader
2 parents c58f77f + 1132171 commit 1055404

File tree

6 files changed

+19
-2
lines changed

6 files changed

+19
-2
lines changed

src/Symfony/Component/Serializer/Mapping/Loader/AnnotationLoader.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
100100
continue;
101101
}
102102

103-
$getAccessor = preg_match('/^(get|)(.+)$/i', $method->name);
104-
if ($getAccessor && 0 !== $method->getNumberOfRequiredParameters()) {
103+
if (0 === stripos($method->name, 'get') && $method->getNumberOfRequiredParameters()) {
105104
continue; /* matches the BC behavior in `Symfony\Component\Serializer\Normalizer\ObjectNormalizer::extractAttributes` */
106105
}
107106

src/Symfony/Component/Serializer/Tests/Fixtures/Annotations/IgnoreDummyAdditionalGetter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ public function getExtraValue(string $parameter)
2020
{
2121
return $parameter;
2222
}
23+
24+
public function setExtraValue2(string $parameter)
25+
{
26+
}
2327
}

src/Symfony/Component/Serializer/Tests/Fixtures/Annotations/IgnoreDummyAdditionalGetterWithoutIgnoreAnnotations.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ public function getExtraValue(string $parameter)
1515
{
1616
return $parameter;
1717
}
18+
19+
public function setExtraValue2(string $parameter)
20+
{
21+
}
1822
}

src/Symfony/Component/Serializer/Tests/Fixtures/Attributes/IgnoreDummyAdditionalGetter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ public function getExtraValue(string $parameter)
1818
{
1919
return $parameter;
2020
}
21+
22+
public function setExtraValue2(string $parameter)
23+
{
24+
}
2125
}

src/Symfony/Component/Serializer/Tests/Fixtures/Attributes/IgnoreDummyAdditionalGetterWithoutIgnoreAnnotations.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ public function getExtraValue(string $parameter)
1515
{
1616
return $parameter;
1717
}
18+
19+
public function setExtraValue2(string $parameter)
20+
{
21+
}
1822
}

src/Symfony/Component/Serializer/Tests/Mapping/Loader/AnnotationLoaderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public function testIgnoreGetterWirhRequiredParameterIfIgnoreAnnotationIsUsed()
157157

158158
$attributes = $classMetadata->getAttributesMetadata();
159159
self::assertArrayNotHasKey('extraValue', $attributes);
160+
self::assertArrayHasKey('extraValue2', $attributes);
160161
}
161162

162163
public function testIgnoreGetterWirhRequiredParameterIfIgnoreAnnotationIsNotUsed()
@@ -166,6 +167,7 @@ public function testIgnoreGetterWirhRequiredParameterIfIgnoreAnnotationIsNotUsed
166167

167168
$attributes = $classMetadata->getAttributesMetadata();
168169
self::assertArrayNotHasKey('extraValue', $attributes);
170+
self::assertArrayHasKey('extraValue2', $attributes);
169171
}
170172

171173
abstract protected function createLoader(): AnnotationLoader;

0 commit comments

Comments
 (0)
0