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

Skip to content

Commit b802d36

Browse files
[VarExporter] espace unicode chars involved in directionality
1 parent efa4ed2 commit b802d36

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Symfony/Component/VarExporter/Internal/Exporter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ public static function export($value, $indent = '')
214214
if (\is_string($value)) {
215215
$code = sprintf("'%s'", addcslashes($value, "'\\"));
216216

217-
$code = preg_replace_callback('/([\0\r\n]++)(.)/', function ($m) use ($subIndent) {
217+
$code = preg_replace_callback("/((?:[\\0\\r\\n]|\u{202A}|\u{202B}|\u{202D}|\u{202E}|\u{2066}|\u{2067}|\u{2068}|\u{202C}|\u{2069})++)(.)/", function ($m) use ($subIndent) {
218218
$m[1] = sprintf('\'."%s".\'', str_replace(
219-
["\0", "\r", "\n", '\n\\'],
220-
['\0', '\r', '\n', '\n"'."\n".$subIndent.'."\\'],
219+
["\0", "\r", "\n", "\u{202A}", "\u{202B}", "\u{202D}", "\u{202E}", "\u{2066}", "\u{2067}", "\u{2068}", "\u{202C}", "\u{2069}", '\n\\'],
220+
['\0', '\r', '\n', '\u{202A}', '\u{202B}', '\u{202D}', '\u{202E}', '\u{2066}', '\u{2067}', '\u{2068}', '\u{202C}', '\u{2069}', '\n"'."\n".$subIndent.'."\\'],
221221
$m[1]
222222
));
223223

src/Symfony/Component/VarExporter/Tests/VarExporterTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ public function provideExport()
240240
yield ['unit-enum', [FooUnitEnum::Bar], true];
241241
}
242242
}
243+
244+
public function testUnicodeDirectionality()
245+
{
246+
$this->assertSame('"\0\r\u{202A}\u{202B}\u{202D}\u{202E}\u{2066}\u{2067}\u{2068}\u{202C}\u{2069}\n"', VarExporter::export("\0\r\u{202A}\u{202B}\u{202D}\u{202E}\u{2066}\u{2067}\u{2068}\u{202C}\u{2069}\n"));
247+
}
243248
}
244249

245250
class MyWakeup

0 commit comments

Comments
 (0)