Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 286253c

Browse files
committed
[Yaml] deprecate "? " starting unquoted strings
1 parent c12727d commit 286253c

File tree

5 files changed

+72
-6
lines changed

5 files changed

+72
-6
lines changed

UPGRADE-3.3.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,12 @@ Workflow
252252
Yaml
253253
----
254254

255-
* Deprecated support for implicitly parsing non-string mapping keys as strings. Mapping keys that are no strings will
256-
lead to a `ParseException` in Symfony 4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
255+
* starting an unquoted string with a question mark followed by a space is
256+
deprecated and will throw a `ParseException` in Symfony 4.0
257+
258+
* Deprecated support for implicitly parsing non-string mapping keys as strings.
259+
Mapping keys that are no strings will lead to a `ParseException` in Symfony
260+
4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
257261
strings.
258262

259263
Before:

UPGRADE-4.0.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,12 @@ Workflow
463463
Yaml
464464
----
465465

466-
* Removed support for implicitly parsing non-string mapping keys as strings. Mapping keys that are no strings will
467-
result in a `ParseException`. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as strings.
466+
* starting an unquoted string with a question mark followed by a space is
467+
throws a `ParseException`
468+
469+
* Removed support for implicitly parsing non-string mapping keys as strings.
470+
Mapping keys that are no strings will result in a `ParseException`. Use the
471+
`PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as strings.
468472

469473
Before:
470474

src/Symfony/Component/Yaml/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ CHANGELOG
44
3.3.0
55
-----
66

7-
* Deprecated support for implicitly parsing non-string mapping keys as strings. Mapping keys that are no strings will
8-
lead to a `ParseException` in Symfony 4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
7+
* starting an unquoted string with a question mark followed by a space is
8+
deprecated and will throw a `ParseException` in Symfony 4.0
9+
10+
* Deprecated support for implicitly parsing non-string mapping keys as strings.
11+
Mapping keys that are no strings will lead to a `ParseException` in Symfony
12+
4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
913
strings.
1014

1115
Before:

src/Symfony/Component/Yaml/Parser.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ public function parse($value, $flags = 0)
144144
$values['value'] = $matches['value'];
145145
}
146146

147+
if (isset($values['value'][1]) && '?' === $values['value'][0] && ' ' === $values['value'][1]) {
148+
@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);
149+
}
150+
147151
// array
148152
if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) {
149153
$data[] = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true), $flags);
@@ -301,6 +305,10 @@ public function parse($value, $flags = 0)
301305
throw new ParseException('Multiple documents are not supported.', $this->currentLineNb + 1, $this->currentLine);
302306
}
303307

308+
if (isset($this->currentLine[1]) && '?' === $this->currentLine[0] && ' ' === $this->currentLine[1]) {
309+
@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);
310+
}
311+
304312
// 1-liner optionally followed by newline(s)
305313
if (is_string($value) && $this->lines[0] === trim($value)) {
306314
try {

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,52 @@ public function testExceptionWhenUsingUnsuportedBuiltInTags()
16401640
$this->parser->parse('!!foo');
16411641
}
16421642

1643+
/**
1644+
* @group legacy
1645+
* @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.
1646+
*/
1647+
public function testComplexMappingThrowsParseException()
1648+
{
1649+
$yaml = <<<YAML
1650+
? "1"
1651+
:
1652+
name: végétalien
1653+
YAML;
1654+
1655+
$this->parser->parse($yaml);
1656+
}
1657+
1658+
/**
1659+
* @group legacy
1660+
* @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.
1661+
*/
1662+
public function testComplexMappingNestedInMappingThrowsParseException()
1663+
{
1664+
$yaml = <<<YAML
1665+
diet:
1666+
? "1"
1667+
:
1668+
name: végétalien
1669+
YAML;
1670+
1671+
$this->parser->parse($yaml);
1672+
}
1673+
1674+
/**
1675+
* @group legacy
1676+
* @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.
1677+
*/
1678+
public function testComplexMappingNestedInSequenceThrowsParseException()
1679+
{
1680+
$yaml = <<<YAML
1681+
- ? "1"
1682+
:
1683+
name: végétalien
1684+
YAML;
1685+
1686+
$this->parser->parse($yaml);
1687+
}
1688+
16431689
private function loadTestsFromFixtureFiles($testsFile)
16441690
{
16451691
$parser = new Parser();

0 commit comments

Comments
 (0)