feature #22059 [Yaml] deprecate "? " starting unquoted strings (xabbuh)
This PR was merged into the 3.3-dev branch.
Discussion
----------
[Yaml] deprecate "? " starting unquoted strings
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | yes
| Tests pass? | yes
| Fixed tickets | #20579
| License | MIT
| Doc PR |
Commits
-------
731a74e79c
[Yaml] deprecate "? " starting unquoted strings
This commit is contained in:
commit
88914a9b1b
@ -252,8 +252,12 @@ Workflow
|
||||
Yaml
|
||||
----
|
||||
|
||||
* Deprecated support for implicitly parsing non-string mapping keys as strings. Mapping keys that are no strings will
|
||||
lead to a `ParseException` in Symfony 4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
|
||||
* Starting an unquoted string with a question mark followed by a space is
|
||||
deprecated and will throw a `ParseException` in Symfony 4.0.
|
||||
|
||||
* Deprecated support for implicitly parsing non-string mapping keys as strings.
|
||||
Mapping keys that are no strings will lead to a `ParseException` in Symfony
|
||||
4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
|
||||
strings.
|
||||
|
||||
Before:
|
||||
|
@ -463,8 +463,12 @@ Workflow
|
||||
Yaml
|
||||
----
|
||||
|
||||
* Removed support for implicitly parsing non-string mapping keys as strings. Mapping keys that are no strings will
|
||||
result in a `ParseException`. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as strings.
|
||||
* Starting an unquoted string with a question mark followed by a space
|
||||
throws a `ParseException`.
|
||||
|
||||
* Removed support for implicitly parsing non-string mapping keys as strings.
|
||||
Mapping keys that are no strings will result in a `ParseException`. Use the
|
||||
`PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as strings.
|
||||
|
||||
Before:
|
||||
|
||||
|
@ -4,8 +4,12 @@ CHANGELOG
|
||||
3.3.0
|
||||
-----
|
||||
|
||||
* Deprecated support for implicitly parsing non-string mapping keys as strings. Mapping keys that are no strings will
|
||||
lead to a `ParseException` in Symfony 4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
|
||||
* Starting an unquoted string with a question mark followed by a space is
|
||||
deprecated and will throw a `ParseException` in Symfony 4.0.
|
||||
|
||||
* Deprecated support for implicitly parsing non-string mapping keys as strings.
|
||||
Mapping keys that are no strings will lead to a `ParseException` in Symfony
|
||||
4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
|
||||
strings.
|
||||
|
||||
Before:
|
||||
|
@ -144,6 +144,10 @@ class Parser
|
||||
$values['value'] = $matches['value'];
|
||||
}
|
||||
|
||||
if (isset($values['value'][1]) && '?' === $values['value'][0] && ' ' === $values['value'][1]) {
|
||||
@trigger_error('Starting an unquoted string with a question mark followed by a space is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
// array
|
||||
if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) {
|
||||
$data[] = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true), $flags);
|
||||
@ -304,6 +308,10 @@ class Parser
|
||||
throw new ParseException('Multiple documents are not supported.', $this->currentLineNb + 1, $this->currentLine);
|
||||
}
|
||||
|
||||
if (isset($this->currentLine[1]) && '?' === $this->currentLine[0] && ' ' === $this->currentLine[1]) {
|
||||
@trigger_error('Starting an unquoted string with a question mark followed by a space is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
// 1-liner optionally followed by newline(s)
|
||||
if (is_string($value) && $this->lines[0] === trim($value)) {
|
||||
try {
|
||||
|
@ -1641,6 +1641,52 @@ YAML
|
||||
$this->parser->parse('!!foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Starting an unquoted string with a question mark followed by a space is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.
|
||||
*/
|
||||
public function testComplexMappingThrowsParseException()
|
||||
{
|
||||
$yaml = <<<YAML
|
||||
? "1"
|
||||
:
|
||||
name: végétalien
|
||||
YAML;
|
||||
|
||||
$this->parser->parse($yaml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Starting an unquoted string with a question mark followed by a space is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.
|
||||
*/
|
||||
public function testComplexMappingNestedInMappingThrowsParseException()
|
||||
{
|
||||
$yaml = <<<YAML
|
||||
diet:
|
||||
? "1"
|
||||
:
|
||||
name: végétalien
|
||||
YAML;
|
||||
|
||||
$this->parser->parse($yaml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Starting an unquoted string with a question mark followed by a space is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.
|
||||
*/
|
||||
public function testComplexMappingNestedInSequenceThrowsParseException()
|
||||
{
|
||||
$yaml = <<<YAML
|
||||
- ? "1"
|
||||
:
|
||||
name: végétalien
|
||||
YAML;
|
||||
|
||||
$this->parser->parse($yaml);
|
||||
}
|
||||
|
||||
private function loadTestsFromFixtureFiles($testsFile)
|
||||
{
|
||||
$parser = new Parser();
|
||||
|
Reference in New Issue
Block a user