Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Yaml] deprecate implicit string casting of mapping keys#21774
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| } | ||
| if (!(Yaml::PARSE_KEYS_AS_STRING &$flags)) { | ||
| $evaluatedKey =self::evaluateScalar($key,$flags,$references); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Shouldn't we also check that$evaluatedKey !== $key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
good idea
src/Symfony/Component/Yaml/Yaml.php Outdated
| constDUMP_MULTI_LINE_LITERAL_BLOCK =128; | ||
| constPARSE_CONSTANT =256; | ||
| constDUMP_EMPTY_ARRAY_AS_SEQUENCE =1024; | ||
| constPARSE_KEYS_AS_STRING =2048; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It seems weird to me to allow something not allowed by the spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
If you just parse the YAML file and do not want to dump it afterwards (or consistency is not important), this may be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Sure but it would work fine without it too so I don't think we should bother.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
But sometimes you are not able to control how the actual YAML structure looks like. I don't think we should make it harder to parse such files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
But then the file is invalid, so shouldn't we consider it must be updated?
If someone has the case why not but it seems a bit too early imo to add this without being sure it will be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Why would it be invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Because it does not respect the spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@GuilhemN the YAML file is not invalid. It is incompatible withPHP datastructures. YAML allowsany value as key of a mapping (including floats, boolean, sequences and mapping).
PHP only supports strings and integers (and it accepts floats but casts them as integer, which is loosing data).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Sure but then do you think we should allow someone to usefalse: foo while it's not possible in php ?
ce0b647 toc82b566Compare| if (!(Yaml::PARSE_KEYS_AS_STRING &$flags)) { | ||
| $evaluatedKey =self::evaluateScalar($key,$flags,$references); | ||
| if ($evaluatedKey !==$key && !is_string($evaluatedKey) && !is_int($evaluatedKey)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
!is_int($evaluated) should be removed imo, it is not supported currently so it should trigger a deprecation too.
c82b566 tofa23697CompareGuilhemN commentedFeb 27, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
What about block mappings? |
81c4c79 to0206282Comparexabbuh commentedMar 6, 2017
tests for block mappings added |
| EOF; | ||
| $expected =array( | ||
| 1 =>'foo', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
That's actually an inconsistency in the current behaviour of the parser for inlined and block mapping (the keys would be parsed as the stringstrue andfalse inside an inlined mapping).
fabpot commentedMar 6, 2017
👍 (with a note added in the CHANGELOG) |
0206282 to3c5d915Comparexabbuh commentedMar 6, 2017
Changelog and upgrade files updated, I also renamed |
fabpot commentedMar 6, 2017
Thank you@xabbuh. |
…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
Since Symfony 3.3 implicit conversion is not enabled by default so weneed to pass that flag manually.Related to:symfony/symfony#21774
Since Symfony 3.3 implicit conversion is not enabled by default so weneed to pass that flag manually.Related to:symfony/symfony#21774
plachance commentedJun 8, 2017
The YAML linter throws the error "Implicit casting of incompatible key type to string on line X is deprecated since version 3.3" when we use !php/const in keys even if the value of the constant is a string. Is it the intended behavior? I don't fully understand the YAML specification on that regard. |
xabbuh commentedJun 13, 2017
@plachance Can you please open a new issue with an example YAML snippet that is causing this deprecation? |
Uh oh!
There was an error while loading.Please reload this page.