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

Skip to content

Commit 3e9c268

Browse files
committed
feature #17809 [Yaml] deprecate starting plain scalars with % characters (xabbuh)
This PR was merged into the 3.1-dev branch. Discussion ---------- [Yaml] deprecate starting plain scalars with % characters | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | symfony/symfony-docs#6269, symfony/symfony-standard#426 | License | MIT | Doc PR | Commits ------- e883a4c deprecate starting plain scalars with % characters
2 parents ddf6207 + e883a4c commit 3e9c268

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

UPGRADE-3.1.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Serializer
3333
Yaml
3434
----
3535

36+
* Deprecated usage of `%` at the beginning of an unquoted string.
37+
3638
* The `Dumper::setIndentation()` method is deprecated and will be removed in
3739
Symfony 4.0. Pass the indentation level to the constructor instead.
3840

UPGRADE-4.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Serializer
3030
Yaml
3131
----
3232

33+
* Starting an unquoted string with `%` leads to a `ParseException`.
34+
3335
* The `Dumper::setIndentation()` method was removed. Pass the indentation
3436
level to the constructor instead.
3537

src/Symfony/Component/Yaml/CHANGELOG.md

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

7+
* Deprecated usage of `%` at the beginning of an unquoted string.
8+
79
* Added support for customizing the YAML parser behavior through an optional bit field:
810

911
```php

src/Symfony/Component/Yaml/Inline.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ public static function parseScalar($scalar, $delimiters = null, $stringDelimiter
289289
throw new ParseException(sprintf('The reserved indicator "%s" cannot start a plain scalar; you need to quote the scalar.', $output[0]));
290290
}
291291

292+
if ($output && '%' === $output[0]) {
293+
@trigger_error('Not quoting a scalar starting with the "%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0.', E_USER_DEPRECATED);
294+
}
295+
292296
if ($evaluate) {
293297
$output = self::evaluateScalar($output, $references);
294298
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,27 @@ public function getScalarIndicators()
252252
return array(array('|'), array('>'));
253253
}
254254

255+
/**
256+
* @group legacy
257+
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
258+
*/
259+
public function testParseUnquotedScalarStartingWithPercentCharacter()
260+
{
261+
$deprecations = array();
262+
set_error_handler(function ($type, $msg) use (&$deprecations) {
263+
if (E_USER_DEPRECATED === $type) {
264+
$deprecations[] = $msg;
265+
}
266+
});
267+
268+
Inline::parse('{ foo: %foo }');
269+
270+
restore_error_handler();
271+
272+
$this->assertCount(1, $deprecations);
273+
$this->assertContains('Not quoting a scalar starting with the "%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0.', $deprecations[0]);
274+
}
275+
255276
public function getTestsForParse()
256277
{
257278
return array(

0 commit comments

Comments
 (0)