Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged

Conversation

@xabbuh
Copy link
Member

@xabbuhxabbuh commentedFeb 27, 2017
edited
Loading

QA
Branch?master
Bug fix?no
New feature?no
BC breaks?no
Deprecations?yes
Tests pass?yes
Fixed tickets#21650 (comment)
LicenseMIT
Doc PR

}

if (!(Yaml::PARSE_KEYS_AS_STRING &$flags)) {
$evaluatedKey =self::evaluateScalar($key,$flags,$references);
Copy link
Contributor

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?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

good idea

constDUMP_MULTI_LINE_LITERAL_BLOCK =128;
constPARSE_CONSTANT =256;
constDUMP_EMPTY_ARRAY_AS_SEQUENCE =1024;
constPARSE_KEYS_AS_STRING =2048;
Copy link
Contributor

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

Copy link
MemberAuthor

@xabbuhxabbuhFeb 27, 2017
edited
Loading

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.

Copy link
Contributor

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.

Copy link
MemberAuthor

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.

Copy link
Contributor

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.

Copy link
MemberAuthor

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?

Copy link
Contributor

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

Copy link
Member

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).

Copy link
Contributor

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 ?

if (!(Yaml::PARSE_KEYS_AS_STRING &$flags)) {
$evaluatedKey =self::evaluateScalar($key,$flags,$references);

if ($evaluatedKey !==$key && !is_string($evaluatedKey) && !is_int($evaluatedKey)) {
Copy link
Contributor

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.

@xabbuhxabbuhforce-pushed thedeprecate-not-usable-key-parsing branch fromc82b566 tofa23697CompareFebruary 27, 2017 11:22
@nicolas-grekasnicolas-grekas added this to the3.3 milestoneFeb 27, 2017
@GuilhemN
Copy link
Contributor

GuilhemN commentedFeb 27, 2017
edited
Loading

What about block mappings?

@xabbuhxabbuhforce-pushed thedeprecate-not-usable-key-parsing branch 3 times, most recently from81c4c79 to0206282CompareMarch 6, 2017 13:37
@xabbuh
Copy link
MemberAuthor

tests for block mappings added

EOF;

$expected =array(
1 =>'foo',
Copy link
MemberAuthor

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
Copy link
Member

👍 (with a note added in the CHANGELOG)

@xabbuhxabbuhforce-pushed thedeprecate-not-usable-key-parsing branch from0206282 to3c5d915CompareMarch 6, 2017 19:18
@xabbuh
Copy link
MemberAuthor

Changelog and upgrade files updated, I also renamedPARSE_KEYS_AS_STRING toPARSE_KEYS_AS_STRINGS for consistency.

@fabpot
Copy link
Member

Thank you@xabbuh.

@fabpotfabpot merged commit3c5d915 intosymfony:masterMar 6, 2017
fabpot added a commit that referenced this pull requestMar 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
@xabbuhxabbuh deleted the deprecate-not-usable-key-parsing branchMarch 6, 2017 19:40
@fabpotfabpot mentioned this pull requestMay 1, 2017
lcobucci added a commit to lcobucci/doctrine2 that referenced this pull requestMay 30, 2017
Since Symfony 3.3 implicit conversion is not enabled by default so weneed to pass that flag manually.Related to:symfony/symfony#21774
lcobucci added a commit to lcobucci/doctrine2 that referenced this pull requestMay 30, 2017
Since Symfony 3.3 implicit conversion is not enabled by default so weneed to pass that flag manually.Related to:symfony/symfony#21774
@plachance
Copy link

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
Copy link
MemberAuthor

@plachance Can you please open a new issue with an example YAML snippet that is causing this deprecation?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

+1 more reviewer

@GuilhemNGuilhemNGuilhemN left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

7 participants

@xabbuh@GuilhemN@fabpot@plachance@stof@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp