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

Skip to content

Commit 162f095

Browse files
committed
[Yaml] deprecated usage of @ and ` at the beginning of an unquoted string
1 parent dc13a99 commit 162f095

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/Symfony/Component/Yaml/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
2.8.0
55
-----
66

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

src/Symfony/Component/Yaml/Inline.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ public static function parseScalar($scalar, $delimiters = null, $stringDelimiter
236236
throw new ParseException(sprintf('Malformed inline YAML string (%s).', $scalar));
237237
}
238238

239+
// a non-quoted string cannot start with @ or ` (reserved)
240+
if ($output && ('@' === $output[0] || '`' === $output[0])) {
241+
@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);
242+
243+
// to be thrown in 3.0
244+
// throw new ParseException(sprintf('The reserved indicator "%s" cannot start a plain scalar; you need to quote the scalar.', $output[0]));
245+
}
246+
239247
if ($evaluate) {
240248
$output = self::evaluateScalar($output, $references);
241249
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,21 @@ public function testParseUnquotedAsteriskFollowedByAComment()
190190
Inline::parse('{ foo: * #foo }');
191191
}
192192

193+
/**
194+
* @group legacy
195+
* @dataProvider getReservedIndicators
196+
* throws \Symfony\Component\Yaml\Exception\ParseException in 3.0
197+
*/
198+
public function testParseUnquotedScalarStartingWithReservedIndicator($indicator)
199+
{
200+
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
201+
}
202+
203+
public function getReservedIndicators()
204+
{
205+
return array(array('@'), array('`'));
206+
}
207+
193208
public function getTestsForParse()
194209
{
195210
return array(

0 commit comments

Comments
 (0)