Skip to content

[Yaml] deprecated usage of @ and ` at the beginning of an unquoted string #16285

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
Oct 28, 2015
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
1 change: 1 addition & 0 deletions src/Symfony/Component/Yaml/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
2.8.0
-----

* Deprecated usage of @ and ` at the beginning of an unquoted string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should escape the backtick here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github seems to handle it just fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only as long as you don't add another one in the file. They handle it only because they cannot find the corresponding one.

* Deprecated non-escaped \ in double-quoted strings when parsing Yaml
("Foo\Var" is not valid whereas "Foo\\Var" is)

Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/Yaml/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ public static function parseScalar($scalar, $delimiters = null, $stringDelimiter
throw new ParseException(sprintf('Malformed inline YAML string (%s).', $scalar));
}

// a non-quoted string cannot start with @ or ` (reserved)
if ($output && ('@' === $output[0] || '`' === $output[0])) {
@trigger_error(sprintf('Not quoting a scalar starting with "%s" is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.', $output[0]), E_USER_DEPRECATED);

// to be thrown in 3.0
// throw new ParseException(sprintf('The reserved indicator "%s" cannot start a plain scalar; you need to quote the scalar.', $output[0]));
}

if ($evaluate) {
$output = self::evaluateScalar($output, $references);
}
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ public function testParseUnquotedAsteriskFollowedByAComment()
Inline::parse('{ foo: * #foo }');
}

/**
* @group legacy
* @dataProvider getReservedIndicators
* throws \Symfony\Component\Yaml\Exception\ParseException in 3.0
*/
public function testParseUnquotedScalarStartingWithReservedIndicator($indicator)
{
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
}

public function getReservedIndicators()
{
return array(array('@'), array('`'));
}

public function getTestsForParse()
{
return array(
Expand Down