From 24f77a01be5a73d420f2220b4cc8bc9fdd8c4ad7 Mon Sep 17 00:00:00 2001 From: Emmanuel BORGES Date: Wed, 6 Mar 2019 12:40:11 +0100 Subject: [PATCH 1/4] Fix getSetMethodNormalizer to correctly ignore the attributes specified in "ignored_attributes" --- UPGRADE-4.2.md | 1 + .../Component/Serializer/Normalizer/GetSetMethodNormalizer.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/UPGRADE-4.2.md b/UPGRADE-4.2.md index 90cd04d01e69..9c9b4c52e7bf 100644 --- a/UPGRADE-4.2.md +++ b/UPGRADE-4.2.md @@ -179,6 +179,7 @@ FrameworkBundle * The `Templating\Helper\TranslatorHelper::transChoice()` method has been deprecated, use the `trans()` one instead with a `%count%` parameter. * Deprecated support for legacy translations directories `src/Resources/translations/` and `src/Resources//translations/`, use `translations/` instead. * Support for the legacy directory structure in `translation:update` and `debug:translation` commands has been deprecated. + * The `GetSetMethodNormalizer` class correctly ignores the attributes specified in "ignored_attributes". HttpFoundation -------------- diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index 07c5671752a9..23b589c2afff 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -110,7 +110,7 @@ protected function extractAttributes($object, $format = null, array $context = [ $attributeName = lcfirst(substr($method->name, 0 === strpos($method->name, 'is') ? 2 : 3)); - if ($this->isAllowedAttribute($object, $attributeName)) { + if ($this->isAllowedAttribute($object, $attributeName, null, $context)) { $attributes[] = $attributeName; } } From 52cfeb31540cbcf0ea9c0a2dad56307cb247d6d1 Mon Sep 17 00:00:00 2001 From: Emmanuel BORGES Date: Thu, 7 Mar 2019 09:08:39 +0100 Subject: [PATCH 2/4] remove comments --- UPGRADE-4.2.md | 1 - 1 file changed, 1 deletion(-) diff --git a/UPGRADE-4.2.md b/UPGRADE-4.2.md index 9c9b4c52e7bf..90cd04d01e69 100644 --- a/UPGRADE-4.2.md +++ b/UPGRADE-4.2.md @@ -179,7 +179,6 @@ FrameworkBundle * The `Templating\Helper\TranslatorHelper::transChoice()` method has been deprecated, use the `trans()` one instead with a `%count%` parameter. * Deprecated support for legacy translations directories `src/Resources/translations/` and `src/Resources//translations/`, use `translations/` instead. * Support for the legacy directory structure in `translation:update` and `debug:translation` commands has been deprecated. - * The `GetSetMethodNormalizer` class correctly ignores the attributes specified in "ignored_attributes". HttpFoundation -------------- From 997adef2a26fe0f9f4998a7763e1d615d9f8209d Mon Sep 17 00:00:00 2001 From: Emmanuel BORGES Date: Thu, 7 Mar 2019 09:40:46 +0100 Subject: [PATCH 3/4] GetSetMethodNormalizer correctly ignore the attributes specified in "ignored_attributes" --- .../Normalizer/GetSetMethodNormalizerTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php index 37948bef4719..babb30a79ccf 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php @@ -329,6 +329,25 @@ public function testLegacyUncallableCallbacks() $this->doTestUncallableCallbacks(true); } + public function testIgnoredAttributesInContext() + { + $ignoredAttributes = ['foo', 'bar', 'baz', 'object']; + $this->createNormalizer([GetSetMethodNormalizer::IGNORED_ATTRIBUTES => $ignoredAttributes]); + + $obj = new GetSetDummy(); + $obj->setFoo('foo'); + $obj->setBar('bar'); + $obj->setCamelCase(true); + + $this->assertEquals( + [ + 'fooBar' => 'foobar', + 'camelCase' => true, + ], + $this->normalizer->normalize($obj, 'any') + ); + } + private function doTestUncallableCallbacks(bool $legacy = false) { $callbacks = ['bar' => null]; From ccda56b75b5b2da142dcf2518773fe0af704348d Mon Sep 17 00:00:00 2001 From: Emmanuel BORGES Date: Wed, 27 Mar 2019 08:09:08 +0100 Subject: [PATCH 4/4] forward value --- .../Component/Serializer/Normalizer/GetSetMethodNormalizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index 23b589c2afff..9fcf58a5b7b2 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -110,7 +110,7 @@ protected function extractAttributes($object, $format = null, array $context = [ $attributeName = lcfirst(substr($method->name, 0 === strpos($method->name, 'is') ? 2 : 3)); - if ($this->isAllowedAttribute($object, $attributeName, null, $context)) { + if ($this->isAllowedAttribute($object, $attributeName, $format, $context)) { $attributes[] = $attributeName; } }