Skip to content

[Yaml] parse omitted inlined mapping values as null #21118

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

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

As @GuilhemN mentioned in #20841 (comment) when using the inline YAML notation, it is currently not possible to completely omit the mapping value to have it parsed as null (you have to pass ~ or null explicitly).

@GuilhemN
Copy link
Contributor

GuilhemN commented Jan 1, 2017

Happy new year ! Best wishes :)

About your change, why not replacing the + here by a * ?

@xabbuh xabbuh force-pushed the inline-null-parsing branch from f172cce to 47afa60 Compare January 1, 2017 13:11
@xabbuh
Copy link
Member Author

xabbuh commented Jan 1, 2017

Happy new year for you too! :)

About your change, why not replacing the + here by a * ?

That's indeed much better. I updated the code accordingly.

@GuilhemN
Copy link
Contributor

GuilhemN commented Jan 1, 2017

Having a null key should be forbidden at the same time as it is not supported by PHP. Not sure how to do it as {: foo} and {'': foo} will be considered the same way while only the second one should be valid.
Same applies for other constants btw {false: foo} should not be valid in a PHP parser but it is equivalent to {'false': foo} currently (keys are not evaluated).

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Jan 2, 2017
@xabbuh xabbuh force-pushed the inline-null-parsing branch from 47afa60 to 0cd3efb Compare January 2, 2017 17:46
@xabbuh xabbuh force-pushed the inline-null-parsing branch from 0cd3efb to 9692f38 Compare January 30, 2017 16:12
@fabpot
Copy link
Member

fabpot commented Feb 16, 2017

@xabbuh any comments regarding the last comment by @GuilhemN?

@xabbuh
Copy link
Member Author

xabbuh commented Feb 16, 2017

@GuilhemN @fabpot As far as I understand the specs the key cannot be omitted in a mapping and it will never be treated as a boolean value (correct me if I am wrong). The YAML parser at http://yaml-online-parser.appspot.com/ seem to confirm this.

@xabbuh xabbuh force-pushed the inline-null-parsing branch from 9692f38 to 8103249 Compare February 16, 2017 22:25
@fabpot
Copy link
Member

fabpot commented Feb 16, 2017

@xabbuh I think that's exactly the problem mentioned by @GuilhemN

You can add the following test, which is valid YAML (and works great):

            'empty key is allowed' => array('{"": "foo"}', array("" => "foo")),

But this one should fail (but it does not):

            'null key is not allowed' => array('{: "foo"}', array(null => "foo")),

@xabbuh xabbuh force-pushed the inline-null-parsing branch from 8103249 to 10e1523 Compare February 17, 2017 07:50
@xabbuh
Copy link
Member Author

xabbuh commented Feb 17, 2017

That's indeed an issue. I opened #21643 to fix this in older maintained versions too (this one should be merged into master as it IMO is a new feature).

@fabpot
Copy link
Member

fabpot commented Mar 1, 2017

@xabbuh Can you rebase and add a note in the CHANGELOG?

@xabbuh xabbuh force-pushed the inline-null-parsing branch from 10e1523 to c473504 Compare March 1, 2017 15:36
@xabbuh
Copy link
Member Author

xabbuh commented Mar 1, 2017

done

@fabpot
Copy link
Member

fabpot commented Mar 1, 2017

Thank you @xabbuh.

@fabpot fabpot merged commit c473504 into symfony:master Mar 1, 2017
fabpot added a commit that referenced this pull request Mar 1, 2017
…abbuh)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[Yaml] parse omitted inlined mapping values as null

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

As @GuilhemN mentioned in #20841 (comment) when using the inline YAML notation, it is currently not possible to completely omit the mapping value to have it parsed as `null` (you have to pass `~` or `null` explicitly).

Commits
-------

c473504 parse omitted inlined mapping values as null
@xabbuh xabbuh deleted the inline-null-parsing branch March 1, 2017 15:41
nicolas-grekas added a commit that referenced this pull request Mar 2, 2017
…agi)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[Yaml] Fix legacy support for omitting mapping key

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

Quick and dirty fix for the failing legacy `InlineTest::testOmittedMappingKeyIsParsedAsColon()` test (failing since #21118).

Ping @xabbuh : I'm not used to the yaml component codebase and it's probably not the most pleasant one to read. 😄 So if you think there is a cleaner way to go, please just close this one in favor of yours.

Commits
-------

d246f2f [Yaml] Fix legacy support for omitting mapping key
@fabpot fabpot mentioned this pull request May 1, 2017
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