Skip to content

[Serializer] MetadataAwareNameConverter: Do not assume that property names are strings #31031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2019

Conversation

soyuka
Copy link
Contributor

@soyuka soyuka commented Apr 9, 2019

Q A
Branch? 4.2 (class introduced in v4.2.3)
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets api-platform/core#2709
License MIT
Doc PR n/a

When this class was introduced, there was an assumption made about the type of propertyNames and therefore a : ?string return type was introduced in the fallbacks/normalization private methods. Because symfony doesn't use strict mode yet (compatibility issues with php IIRC), when using a non-string property name (for example the integer 0 which is a valid property name in an array), it will convert the integer to a string.
This is not good, especially if you have a name converter that returns the given property name (ie no transformation) you'll have it's type changed which isn't correct.

I've discovered this bug while working on adding this name converter in api platform (api-platform/core#2709).

@fabpot
Copy link
Member

fabpot commented Apr 10, 2019

Thank you @soyuka.

@fabpot fabpot merged commit af1e136 into symfony:4.2 Apr 10, 2019
fabpot added a commit that referenced this pull request Apr 10, 2019
…t property names are strings (soyuka)

This PR was merged into the 4.2 branch.

Discussion
----------

[Serializer]  MetadataAwareNameConverter: Do not assume that property names are strings

| Q             | A
| ------------- | ---
| Branch?       | 4.2 (class introduced in v4.2.3)
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | api-platform/core#2709
| License       | MIT
| Doc PR        | n/a

When this class was introduced, there was an assumption made about the type of `propertyNames` and therefore a `: ?string` return type was introduced in the fallbacks/normalization private methods. Because symfony doesn't use strict mode yet (compatibility issues with php IIRC), when using a non-string property name (for example the integer `0` which is a valid property name in an array), it will convert the integer to a string.
This is not good, especially if you have a name converter that returns the given property name (ie no transformation) you'll have it's type changed which isn't correct.

I've discovered this bug while working on adding this name converter in api platform (api-platform/core#2709).

Commits
-------

af1e136 MetadataAwareNameConverter: Do not assume that property names are strings
@soyuka soyuka deleted the fix-metadataawarenameconverter branch April 10, 2019 13:26
@fabpot fabpot mentioned this pull request Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants