Skip to content

[Yaml] add tests for specific mapping keys #21650

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
Mar 1, 2017

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Feb 17, 2017

Q A
Branch? 2.7
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets see #21643 (comment)
License MIT
Doc PR


public function testBooleanMappingKeysAreConvertedToStrings()
{
$this->assertSame(array('false' => 'foo'), Inline::parse('{false: foo}'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would test both true and false

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, did that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should not be allowed actually, keys should be treated like any other value and evaluated, so boolean should not be allowed as a key.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if we want to forbid using boolean as keys because they are not supported in PHP, this must be done in master with a deprecation.
Having these tests in our maintenance branches are good to avoid introducing BC breaks by mistake.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, if we start evaluating, we would also have to forbid floats to avoid breaking BC.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we don't know if the user wants false to be dumped as a string or as the boolean value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a bool key is supported neither in php nor in symfony, i think we can safelly guess the user wants a string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is this is broken if they use the same YAML file with another language that supports boolean keys as parsing and then dumping the parsed structure changes the result for other languages. Deprecating the current behaviour doesn't change anything about the inconsistency between the different languages, but it makes it obvious and prevents hard to discover bugs related to these inconsistencies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point too... Sounds complicated to fix after all, should we consider it as won't fix or would you prefer deprecating evaluated keys as I proposed at the beginning (note that this second solution may cause a small overhead)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that we deprecate parsing keys as strings implicitly and make this an opt-in feature instead (see #21774).

@xabbuh xabbuh force-pushed the mapping-keys-tests branch from 5a6f4e3 to b8e0d70 Compare February 17, 2017 13:54
@fabpot
Copy link
Member

fabpot commented Mar 1, 2017

Thank you @xabbuh.

@fabpot fabpot merged commit b8e0d70 into symfony:2.7 Mar 1, 2017
fabpot added a commit that referenced this pull request Mar 1, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

[Yaml] add tests for specific mapping keys

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | see #21643 (comment)
| License       | MIT
| Doc PR        |

Commits
-------

b8e0d70 [Yaml] add tests for specific mapping keys
@xabbuh xabbuh deleted the mapping-keys-tests branch March 1, 2017 14:50
fabpot added a commit that referenced this pull request Mar 6, 2017
…ys (xabbuh)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[Yaml] deprecate implicit string casting of mapping keys

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #21650 (comment)
| License       | MIT
| Doc PR        |

Commits
-------

3c5d915 deprecate implicit string casting of mapping keys
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.

6 participants