File tree Expand file tree Collapse file tree 4 files changed +38
-2
lines changed
src/Symfony/Component/Yaml Expand file tree Collapse file tree 4 files changed +38
-2
lines changed Original file line number Diff line number Diff line change 11CHANGELOG
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+
4102.1.0
511-----
612
Original file line number Diff line number Diff 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+ )
Original file line number Diff line number Diff line change @@ -72,6 +72,23 @@ 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+
84+ /**
85+ * @expectedException \Symfony\Component\Yaml\Exception\ParseException
86+ */
87+ public function testParseScalarWithNonEscapedBlackslashAtTheEndShouldThrowException ()
88+ {
89+ Inline::parse ('"Foo \\" ' );
90+ }
91+
7592 /**
7693 * @expectedException \Symfony\Component\Yaml\Exception\ParseException
7794 */
Original file line number Diff line number Diff 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 \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}|. ) " ;
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 will throw a ParseException in 3.0. ' , E_USER_DEPRECATED );
123128 }
124129 }
125130
You can’t perform that action at this time.
0 commit comments