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

Skip to content

Commit 8823166

Browse files
committed
[Yaml] deprecated non-escaped \ in double-quoted strings when parsing
1 parent 6907498 commit 8823166

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

src/Symfony/Component/Yaml/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
2.8.0
5+
-----
6+
7+
* Deprecated non-escaped \ in double-quoted strings when parsing Yaml
8+
("Foo\Var" is not valid whereas "Foo\\Var" is)
9+
410
2.1.0
511
-----
612

src/Symfony/Component/Yaml/Tests/Fixtures/escapedCharacters.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,11 @@ php: |
145145
array(
146146
'double' => "some value\n \"some quoted string\" and 'some single quotes one'"
147147
)
148+
---
149+
test: Backslashes
150+
yaml: |
151+
{ single: 'foo\Var', no-quotes: foo\Var, double: "foo\\Var" }
152+
php: |
153+
array(
154+
'single' => 'foo\Var', 'no-quotes' => 'foo\Var', 'double' => 'foo\Var'
155+
)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ public function testHashStringsResemblingExponentialNumericsShouldNotBeChangedTo
7272
$this->assertSame($value, Inline::parse(Inline::dump($value)));
7373
}
7474

75+
/**
76+
* @group legacy
77+
* throws \Symfony\Component\Yaml\Exception\ParseException in 3.0
78+
*/
79+
public function testParseScalarWithNonEscapedBlackslashShouldThrowException()
80+
{
81+
Inline::parse('"Foo\Var"');
82+
}
83+
7584
/**
7685
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
7786
*/

src/Symfony/Component/Yaml/Unescaper.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Unescaper
3232
/**
3333
* Regex fragment that matches an escaped character in a double quoted string.
3434
*/
35-
const REGEX_ESCAPED_CHARACTER = "\\\\([0abt\tnvfre \\\"\\/\\\\N_LP]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})";
35+
const REGEX_ESCAPED_CHARACTER = "\\\\(x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|.|)";
3636

3737
/**
3838
* Unescapes a single quoted string.
@@ -70,10 +70,13 @@ public function unescapeDoubleQuotedString($value)
7070
* @param string $value An escaped character
7171
*
7272
* @return string The unescaped character
73+
*
74+
* @internal This method is public to be usable as callback. It should not
75+
* be used in user code. Should be changed in 3.0.
7376
*/
7477
public function unescapeCharacter($value)
7578
{
76-
switch ($value{1}) {
79+
switch ($value[1]) {
7780
case '0':
7881
return "\x0";
7982
case 'a':
@@ -120,6 +123,8 @@ public function unescapeCharacter($value)
120123
return self::utf8chr(hexdec(substr($value, 2, 4)));
121124
case 'U':
122125
return self::utf8chr(hexdec(substr($value, 2, 8)));
126+
default:
127+
@trigger_error('Not escaping a backslash in a double-quoted string is deprecated since Symfony 2.8 and throw a ParseException in 3.0.', E_USER_DEPRECATED);
123128
}
124129
}
125130

0 commit comments

Comments
 (0)