Skip to content

Commit 44e5458

Browse files
committed
Diagnostics\Dumper: non-binary UTF-8 strings are not escaped at all
1 parent 9d68e57 commit 44e5458

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/PhpGenerator/Helpers.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,15 @@ private static function _dump(&$var, $level = 0)
5151
} elseif (is_string($var) && (preg_match('#[^\x09\x20-\x7E\xA0-\x{10FFFF}]#u', $var) || preg_last_error())) {
5252
static $table;
5353
if ($table === NULL) {
54-
foreach (range("\x00", "\xFF") as $ch) {
55-
$table[$ch] = ord($ch) < 32 || ord($ch) >= 127
56-
? '\\x' . str_pad(dechex(ord($ch)), 2, '0', STR_PAD_LEFT)
57-
: $ch;
54+
foreach (array_merge(range("\x00", "\x1F"), range("\x7F", "\xFF")) as $ch) {
55+
$table[$ch] = '\x' . str_pad(dechex(ord($ch)), 2, '0', STR_PAD_LEFT);
5856
}
57+
$table['\\'] = '\\\\';
5958
$table["\r"] = '\r';
6059
$table["\n"] = '\n';
6160
$table["\t"] = '\t';
62-
$table['$'] = '\\$';
63-
$table['\\'] = '\\\\';
64-
$table['"'] = '\\"';
61+
$table['$'] = '\$';
62+
$table['"'] = '\"';
6563
}
6664
return '"' . strtr($var, $table) . '"';
6765

0 commit comments

Comments
 (0)