Skip to content

[Yaml] deprecate starting plain scalars with % characters #17809

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

Merged
merged 1 commit into from
Feb 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADE-3.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Serializer
Yaml
----

* Deprecated usage of `%` at the beginning of an unquoted string.

* The `Dumper::setIndentation()` method is deprecated and will be removed in
Symfony 4.0. Pass the indentation level to the constructor instead.

Expand Down
2 changes: 2 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Serializer
Yaml
----

* Starting an unquoted string with `%` leads to a `ParseException`.

* The `Dumper::setIndentation()` method was removed. Pass the indentation
level to the constructor instead.

Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Yaml/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CHANGELOG
3.1.0
-----

* Deprecated usage of `%` at the beginning of an unquoted string.

* Added support for customizing the YAML parser behavior through an optional bit field:

```php
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Yaml/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ public static function parseScalar($scalar, $delimiters = null, $stringDelimiter
throw new ParseException(sprintf('The reserved indicator "%s" cannot start a plain scalar; you need to quote the scalar.', $output[0]));
}

if ($output && '%' === $output[0]) {
@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);
}

if ($evaluate) {
$output = self::evaluateScalar($output, $references);
}
Expand Down
21 changes: 21 additions & 0 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,27 @@ public function getScalarIndicators()
return array(array('|'), array('>'));
}

/**
* @group legacy
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
*/
public function testParseUnquotedScalarStartingWithPercentCharacter()
{
$deprecations = array();
set_error_handler(function ($type, $msg) use (&$deprecations) {
if (E_USER_DEPRECATED === $type) {
$deprecations[] = $msg;
}
});

Inline::parse('{ foo: %foo }');

restore_error_handler();

$this->assertCount(1, $deprecations);
$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]);
}

public function getTestsForParse()
{
return array(
Expand Down