Permalink
Browse files

minor #27317 [VarDumper] make control characters non-selectable in HT…

…ML (kiler129)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[VarDumper] make control characters non-selectable in HTML

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | maybe
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23921
| License       | MIT
| Doc PR        | -

### Overview
This fixes long term annoyance with control characters in dumps. It makes dumps unusable to use with e.g. SQLs, since copying them will leave `\n` (and others).

### Changes
This PR does three things:
1. Adds special class of characters abbreviated as `ctrl` (cosmetic, already exists in fact but it's not exposed in HTML)
2. Makes control characters non-selectable
3. Changes color of control character from default orange to grey (used by Symfony.com dark theme) which improves UX by showing *"hey, this is something special"*

### Preview
**Inline dump**
<img width="243" alt="screenshot 2018-05-19 17 26 18" src="https://user-images.githubusercontent.com/1227834/40273711-7d963450-5b8b-11e8-843a-dda1e2719b59.png">

**Web Profiler**
<img width="418" alt="screenshot 2018-05-19 17 38 36" src="https://user-images.githubusercontent.com/1227834/40273714-86b9cfec-5b8b-11e8-898b-b7cb5f150a72.png">
<img width="533" alt="screenshot 2018-05-19 17 20 42" src="https://user-images.githubusercontent.com/1227834/40273720-a2370852-5b8b-11e8-88c7-aed9281cc056.png">

**Dump Server**
<img width="194" alt="screenshot 2018-05-19 17 30 12" src="https://user-images.githubusercontent.com/1227834/40273722-aa444686-5b8b-11e8-9ae9-ea2eebb3368d.png">

Commits
-------

b0d4c99 [VarDumper] make control characters non-selectable in HTML
  • Loading branch information...
nicolas-grekas committed Jul 1, 2018
2 parents 80aa8df + b0d4c99 commit 83d116b031ddb8920b715268fdc1d19c3ae7d86b
@@ -44,6 +44,7 @@ class HtmlDumper extends CliDumper
'key' => 'color:#56DB3A',
'index' => 'color:#1299DA',
'ellipsis' => 'color:#FF8400',
'ns' => 'user-select:none;',
);
private $displayOptions = array(
@@ -837,9 +838,21 @@ protected function style($style, $value, $attr = array())
}
$v = "<span class=sf-dump-{$style}>".preg_replace_callback(static::$controlCharsRx, function ($c) use ($map) {
$s = '<span class=sf-dump-default>';
$s = $b = '<span class="sf-dump-default';
$c = $c[$i = 0];
if ($ns = "\r" === $c[$i] || "\n" === $c[$i])) {
$s .= ' sf-dump-ns';
}
$s .= '">';
do {
if (("\r" === $c[$i] || "\n" === $c[$i]) !== $ns) {
$s .= '</span>'.$b;
if ($ns = !$ns) {
$s .= ' sf-dump-ns';
}
$s .= '">';
}
$s .= isset($map[$c[$i]]) ? $map[$c[$i]] : sprintf('\x%02X', ord($c[$i]));
} while (isset($c[++$i]));
@@ -127,3 +127,4 @@ pre.sf-dump {
.dumped-tag > .sf-dump .sf-dump-ref { color: #6E6E6E; }
.dumped-tag > .sf-dump .sf-dump-ellipsis { color: #CC7832; max-width: 100em; }
.dumped-tag > .sf-dump .sf-dump-ellipsis-path { max-width: 5em; }
.dumped-tag > .sf-dump .sf-dump-ns { user-select: none; }
@@ -61,7 +61,10 @@ public function testGet()
5 => -INF
6 => {$intMax}
"str" => "déjà\\n"
7 => b"é\\x00"
7 => b"""
é\\x00test\\t\\n
ing
"""
"[]" => []
"res" => stream resource {@{$res}
%A wrapper_type: "plainfile"
@@ -63,8 +63,11 @@ public function testGet()
<span class=sf-dump-key>4</span> => <span class=sf-dump-num>INF</span>
<span class=sf-dump-key>5</span> => <span class=sf-dump-num>-INF</span>
<span class=sf-dump-key>6</span> => <span class=sf-dump-num>{$intMax}</span>
"<span class=sf-dump-key>str</span>" => "<span class=sf-dump-str title="5 characters">d&%s;j&%s;<span class=sf-dump-default>\\n</span></span>"
<span class=sf-dump-key>7</span> => b"<span class=sf-dump-str title="2 binary or non-UTF-8 characters">&%s;<span class=sf-dump-default>\\x00</span></span>"
"<span class=sf-dump-key>str</span>" => "<span class=sf-dump-str title="5 characters">d&%s;j&%s;<span class="sf-dump-default sf-dump-ns">\\n</span></span>"
<span class=sf-dump-key>7</span> => b"""
<span class=sf-dump-str title="11 binary or non-UTF-8 characters">&eacute;<span class="sf-dump-default">\\x00</span>test<span class="sf-dump-default">\\t</span><span class="sf-dump-default sf-dump-ns">\\n</span></span>
<span class=sf-dump-str title="11 binary or non-UTF-8 characters">ing</span>
"""
"<span class=sf-dump-key>[]</span>" => []
"<span class=sf-dump-key>res</span>" => <span class=sf-dump-note>stream resource</span> <a class=sf-dump-ref>@{$res}</a><samp>
%A <span class=sf-dump-meta>wrapper_type</span>: "<span class=sf-dump-str title="9 characters">plainfile</span>"
@@ -17,7 +17,7 @@ class DumbFoo
$var = array(
'number' => 1, null,
'const' => 1.1, true, false, NAN, INF, -INF, PHP_INT_MAX,
'str' => "déjà\n", "\xE9\x00",
'str' => "déjà\n", "\xE9\x00test\t\ning",
'[]' => array(),
'res' => $g,
'obj' => $foo,

0 comments on commit 83d116b

Please sign in to comment.