-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Yaml] Recommend using quotes instead of PARSE_KEYS_AS_STRINGS #22948
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
use Symfony\Component\Serializer\Mapping\AttributeMetadata; | ||
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface; | ||
use Symfony\Component\Yaml\Parser; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
/** | ||
* YAML File Loader. | ||
|
@@ -114,7 +113,7 @@ private function getClassesFromYaml() | |
$this->yamlParser = new Parser(); | ||
} | ||
|
||
$classes = $this->yamlParser->parse(file_get_contents($this->file), Yaml::PARSE_KEYS_AS_STRINGS); | ||
$classes = $this->yamlParser->parse(file_get_contents($this->file)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed |
||
|
||
if (empty($classes)) { | ||
return array(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -490,7 +490,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar | |
@trigger_error('Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0.', E_USER_DEPRECATED); | ||
} | ||
|
||
if (!(Yaml::PARSE_KEYS_AS_STRINGS & $flags)) { | ||
if (!$isKeyQuoted) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added because quoted keys should not be evaluated |
||
$evaluatedKey = self::evaluateScalar($key, $flags, $references); | ||
|
||
if ('' !== $key && $evaluatedKey !== $key && !is_string($evaluatedKey) && !is_int($evaluatedKey)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,10 @@ public function parse($value, $flags = 0) | |
} | ||
} | ||
|
||
if (Yaml::PARSE_KEYS_AS_STRINGS & $flags) { | ||
@trigger_error('Using the Yaml::PARSE_KEYS_AS_STRINGS flag is deprecated since version 3.4 as it will be removed in 4.0. Quote your keys when they are evaluable instead.', E_USER_DEPRECATED); | ||
} | ||
|
||
if (false === preg_match('//u', $value)) { | ||
throw new ParseException('The YAML value does not appear to be valid UTF-8.'); | ||
} | ||
|
@@ -236,7 +240,7 @@ private function doParse($value, $flags) | |
throw $e; | ||
} | ||
|
||
if (!(Yaml::PARSE_KEYS_AS_STRINGS & $flags) && !is_string($key) && !is_int($key)) { | ||
if (!is_string($key) && !is_int($key)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you sure about this change ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, evaluable keys are no longer allowed unless they're quoted, even when using |
||
$keyType = is_numeric($key) ? 'numeric key' : 'non-string key'; | ||
@trigger_error(sprintf('Implicit casting of %s to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.', $keyType), E_USER_DEPRECATED); | ||
} | ||
|
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.
isn't this a BC break ?
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.
Not more than when we added it in 3.3 (for instance
!str foo
in routing files was parsed as"foo"
in 3.2 and is as"!str foo"
since 3.3). Reverting this change is in fact more intuitive imo as it does make the parser always spec compliant.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 do this change in #23635 then?
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.
I prefer doing this in a minor but if you insist I can of course do it in 3.3.
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.
The
use
statement can be removed too?