File tree 4 files changed +30
-2
lines changed
src/Symfony/Component/Yaml
4 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 1
1
CHANGELOG
2
2
=========
3
3
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
+
4
10
2.1.0
5
11
-----
6
12
Original file line number Diff line number Diff line change @@ -145,3 +145,11 @@ php: |
145
145
array(
146
146
'double' => "some value\n \"some quoted string\" and 'some single quotes one'"
147
147
)
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
+ )
Original file line number Diff line number Diff line change @@ -72,6 +72,15 @@ public function testHashStringsResemblingExponentialNumericsShouldNotBeChangedTo
72
72
$ this ->assertSame ($ value , Inline::parse (Inline::dump ($ value )));
73
73
}
74
74
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
+
75
84
/**
76
85
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
77
86
*/
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ class Unescaper
32
32
/**
33
33
* Regex fragment that matches an escaped character in a double quoted string.
34
34
*/
35
- const REGEX_ESCAPED_CHARACTER = "\\\\([0abt \t nvfre \\\"\\ / \\\\ 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}|.| ) " ;
36
36
37
37
/**
38
38
* Unescapes a single quoted string.
@@ -70,10 +70,13 @@ public function unescapeDoubleQuotedString($value)
70
70
* @param string $value An escaped character
71
71
*
72
72
* @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.
73
76
*/
74
77
public function unescapeCharacter ($ value )
75
78
{
76
- switch ($ value{ 1 } ) {
79
+ switch ($ value[ 1 ] ) {
77
80
case '0 ' :
78
81
return "\x0" ;
79
82
case 'a ' :
@@ -120,6 +123,8 @@ public function unescapeCharacter($value)
120
123
return self ::utf8chr (hexdec (substr ($ value , 2 , 4 )));
121
124
case 'U ' :
122
125
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 );
123
128
}
124
129
}
125
130
You can’t perform that action at this time.
0 commit comments