8000 feature #22059 [Yaml] deprecate "? " starting unquoted strings (xabbuh) · symfony/symfony@88914a9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 88914a9

Browse files
committed
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 ------- 731a74e [Yaml] deprecate "? " starting unquoted strings
2 parents 4d48b58 + 731a74e commit 88914a9

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
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);
@@ -304,6 +308,10 @@ public function parse($value, $flags = 0)
304308
throw new ParseException('Multiple documents are not supported.', $this->currentLineNb + 1, $this->currentLine);
305309
}
306310

311+
if (isset($this->currentLine[1]) && '?' === $this->currentLine[0] && ' ' === $this->currentLine[1]) {
312+
@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);
313+
}
314+
307315
// 1-liner optionally followed by newline(s)
308316
if (is_string($value) && $this->lines[0] === trim($value)) {
309317
try {

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

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

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

0 commit comments

Comments
 (0)
0