Skip to content

Commit 395783f

Browse files
committed
Apply nicolas-grekas patch
1 parent 1bdee8f commit 395783f

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

src/Symfony/Component/VarDumper/Dumper/CliDumper.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class CliDumper extends AbstractDumper
5151
"\r" => '\r',
5252
"\033" => '\e',
5353
];
54+
protected static $unicodeCharsRx = "/[\u{00A0}\u{00AD}\u{034F}\u{061C}\u{115F}\u{1160}\u{17B4}\u{17B5}\u{180E}\u{2000}-\u{200F}\u{202F}\u{205F}\u{2060}-\u{2064}\u{206A}-\u{206F}\u{3000}\u{2800}\u{3164}\u{FEFF}\u{FFA0}\u{1D159}\u{1D173}-\u{1D17A}]/u";
5455

5556
protected $collapseNextHash = false;
5657
protected $expandNextHash = false;
@@ -224,7 +225,6 @@ public function dumpString(Cursor $cursor, string $str, bool $bin, int $cut)
224225
$this->line .= $this->indentPad;
225226
}
226227
if ('' !== $str) {
227-
$str = $this->replaceInvisibleCharacters($str);
228228
$this->line .= $this->style('str', $str, $attr);
229229
}
230230
if ($i++ == $m) {
@@ -349,7 +349,6 @@ protected function dumpKey(Cursor $cursor)
349349
if (\is_int($key)) {
350350
$this->line .= $this->style($style, $key).' => ';
351351
} else {
352-
$key = $this->replaceInvisibleCharacters($key);
353352
$this->line .= $bin.'"'.$this->style($style, $key).'" => ';
354353
}
355354
break;
@@ -452,6 +451,14 @@ protected function style(string $style, string $value, array $attr = []): string
452451
return $s.$endCchr;
453452
}, $value, -1, $cchrCount);
454453

454+
if (!($attr['binary'] ?? false)) {
455+
$value = preg_replace_callback(static::$unicodeCharsRx, function ($c) use (&$cchrCount, $startCchr, $endCchr) {
456+
++$cchrCount;
457+
458+
return $startCchr.'\u{'.strtoupper(dechex(mb_ord($c[0]))).'}'.$endCchr;
459+
}, $value);
460+
}
461+
455462
if ($this->colors) {
456463
if ($cchrCount && "\033" === $value[0]) {
457464
$value = substr($value, \strlen($startCchr));
@@ -615,16 +622,4 @@ private function getSourceLink(string $file, int $line)
615622

616623
return false;
617624
}
618-
619-
/**
620-
* Replace invisible character by the hexadecimal representation of the codepoint.
621-
*/
622-
private function replaceInvisibleCharacters(string $input): string
623-
{
624-
$invisibleCharacters = [''];
625-
626-
return preg_replace_callback('/'.implode('|', $invisibleCharacters).'/u', static function (array $matches): string {
627-
return sprintf('\u{%s}', dechex(mb_ord($matches[0])));
628-
}, $input);
629-
}
630625
}

src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testGet()
6666
é\\x01test\\t\\n
6767
ing
6868
"""
69-
"bo\\u{feff}m" => "te\\u{feff}st"
69+
"bo\\u{FEFF}m" => "te\\u{FEFF}st"
7070
"[]" => []
7171
"res" => stream resource {@{$res}
7272
%A wrapper_type: "plainfile"

src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testGet()
6969
<span class=sf-dump-str title="11 binary or non-UTF-8 characters">&#233;<span class="sf-dump-default">\\x01</span>test<span class="sf-dump-default">\\t</span><span class="sf-dump-default sf-dump-ns">\\n</span></span>
7070
<span class=sf-dump-str title="11 binary or non-UTF-8 characters">ing</span>
7171
"""
72-
"<span class=sf-dump-key>bo\\u{feff}m</span>" => "<span class=sf-dump-str title="5 characters">te\\u{feff}st</span>"
72+
"<span class=sf-dump-key>bo\\u{FEFF}m</span>" => "<span class=sf-dump-str title="5 characters">te\\u{FEFF}st</span>"
7373
"<span class=sf-dump-key>[]</span>" => []
7474
"<span class=sf-dump-key>res</span>" => <span class=sf-dump-note>stream resource</span> <a class=sf-dump-ref>@{$res}</a><samp data-depth=2 class=sf-dump-compact>
7575
%A <span class=sf-dump-meta>wrapper_type</span>: "<span class=sf-dump-str title="9 characters">plainfile</span>"

0 commit comments

Comments
 (0)