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

This PR was merged into the 2.8 branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #16234
| License       | MIT
| Doc PR        | n/a

Commits
-------

7fee29f [Yaml] deprecated usage of @ and ` at the beginning of an unquoted string
This commit is contained in:
Fabien Potencier 2015-10-27 22:26:40 -07:00
commit 44b3f63f30
3 changed files with 24 additions and 0 deletions

View File

@ -4,6 +4,7 @@ CHANGELOG
2.8.0
-----
* Deprecated usage of @ and ` at the beginning of an unquoted string
* Deprecated non-escaped \ in double-quoted strings when parsing Yaml
("Foo\Var" is not valid whereas "Foo\\Var" is)

View File

@ -236,6 +236,14 @@ class Inline
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);
}

View File

@ -190,6 +190,21 @@ class InlineTest extends \PHPUnit_Framework_TestCase
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(