@@ -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}
0 commit comments