8000 [VarDumper] edge case fixes · symfony/symfony@10943d9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 10943d9

Browse files
[VarDumper] edge case fixes
1 parent 15dfb06 commit 10943d9

File tree

15 files changed

+58
-50
lines changed

15 files changed

+58
-50
lines changed

src/Symfony/Bundle/DebugBundle/DependencyInjection/Configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public function getConfigTreeBuilder()
4141
->min(-1)
4242
->defaultValue(-1)
4343
->end()
44-
->end();
44+
->end()
45+
;
4546

4647
return $treeBuilder;
4748
}

src/Symfony/Bundle/DebugBundle/Resources/views/Profiler/dump.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<div class="sf-toolbar-info-piece">
1919
in
2020
{% if dump.file %}
21-
{% set link = dump.file|file_link(dump.line) }} %}
21+
{% set link = dump.file|file_link(dump.line) %}
2222
{% if link %}
2323
<a href="{{ link }}" title="{{ dump.file }}">{{ dump.name }}</a>
2424
{% else %}
@@ -76,7 +76,7 @@
7676
<li class="sf-dump sf-reset">
7777
in
7878
{% if dump.line %}
79-
{% set link = dump.file|file_link(dump.line) }} %}
79+
{% set link = dump.file|file_link(dump.line) %}
8080
{% if link %}
8181
<a href="{{ link }}" title="{{ dump.file }}">{{ dump.name }}</a>
8282
{% else %}

src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\HttpFoundation\Response;
1616
use Symfony\Component\Stopwatch\Stopwatch;
1717
use Symfony\Component\VarDumper\Cloner\Data;
18-
use Symfony\Component\VarDumper\Dumper\JsonDumper;
1918
use Symfony\Component\VarDumper\Dumper\CliDumper;
2019
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
2120
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
@@ -158,8 +157,6 @@ public function getDumps($format, $maxDepthLimit = -1, $maxItemsPerDepth = -1)
158157
{
159158
if ('html' === $format) {
160159
$dumper = new HtmlDumper();
161-
} elseif ('json' === $format) {
162-
$dumper = new JsonDumper();
163160
} else {
164161
throw new \InvalidArgumentException(sprintf('Invalid dump format: %s', $format));
165162
}

src/Symfony/Component/VarDumper/Caster/CasterStub.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ class CasterStub extends Stub
2222
{
2323
public function __construct($value, $class = '')
2424
{
25+
$this->class = $class;
26+
$this->value = $value;
27+
2528
switch (gettype($value)) {
2629
case 'object':
2730
$this->type = self::TYPE_OBJECT;
2831
$this->class = get_class($value);
29-
$this->value = spl_object_hash($value);
3032
$this->cut = -1;
3133
break;
3234

@@ -40,7 +42,6 @@ public function __construct($value, $class = '')
4042
case 'unknown type':
4143
$this->type = self::TYPE_RESOURCE;
4244
$this->class = @get_resource_type($value);
43-
$this->value = (int) $value;
4445
$this->cut = -1;
4546
break;
4647

@@ -49,13 +50,8 @@ public function __construct($value, $class = '')
4950
$this->type = self::TYPE_STRING;
5051
$this->class = preg_match('//u', $value) ? self::STRING_UTF8 : self::STRING_BINARY;
5152
$this->cut = self::STRING_BINARY === $this->class ? strlen($value) : (function_exists('iconv_strlen') ? iconv_strlen($value, 'UTF-8') : -1);
52-
break;
53+
$this->value = '';
5354
}
54-
// No break;
55-
56-
default:
57-
$this->class = $class;
58-
$this->value = $value;
5955
break;
6056
}
6157
}

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ abstract protected function doClone($var);
174174
/**
175175
* Casts an object to an array representation.
176176
*
177-
* @param object $obj The object itself.
178177
* @param Stub $stub The Stub for the casted object.
179178
* @param bool $isNested True if the object is nested in the dumped structure.
180179
*
181180
* @return array The object casted as array.
182181
*/
183-
protected function castObject($obj, Stub $stub, $isNested)
182+
protected function castObject(Stub $stub, $isNested)
184183
{
184+
$obj = $stub->value;
185185
$class = $stub->class;
186186

187187
if (isset($this->classInfo[$class])) {
@@ -225,15 +225,15 @@ protected function castObject($obj, Stub $stub, $isNested)
225225
/**
226226
* Casts a resource to an array representation.
227227
*
228-
* @param resource $res The resource.
229228
* @param Stub $stub The Stub for the casted resource.
230229
* @param bool $isNested True if the object is nested in the dumped structure.
231230
*
232231
* @return array The resource casted as array.
233232
*/
234-
protected function castResource($res, Stub $stub, $isNested)
233+
protected function castResource(Stub $stub, $isNested)
235234
{
236235
$a = array();
236+
$res = $stub->value;
237237
$type = $stub->class;
238238

239239
if (!empty($this->casters[':'.$type])) {

src/Symfony/Component/VarDumper/Cloner/Data.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ private function dumpChildren($dumper, $parentCursor, &$refs, $children, $hashCu
200200
*/
201201
public static function utf8Encode($s)
202202
{
203-
if (function_exists('iconv')) {
204-
return iconv('CP1252', 'UTF-8', $s);
203+
if (function_exists('mb_convert_encoding')) {
204+
return mb_convert_encoding($s, 'UTF-8', 'CP1252');
205205
}
206206

207207
$s .= $s;

src/Symfony/Component/VarDumper/Cloner/ExtCloner.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,26 @@ protected function doClone($var)
9595
$stub = new Stub();
9696
$stub->type = Stub::TYPE_OBJECT;
9797
$stub->class = $zval['object_class'];
98-
$stub->value = $h;
99-
$a = $this->castObject($v, $stub, 0 < $i);
100-
if (Stub::TYPE_OBJECT !== $stub->type) {
101-
break;
98+
$stub->value = $v;
99+
$a = $this->castObject($stub, 0 < $i);
100+
if ($v !== $stub->value) {
101+
if (Stub::TYPE_OBJECT !== $stub->type) {
102+
break;
103+
}
104+
$h = spl_object_hash($stub->value);
102105
}
103-
$h = $stub->value;
104-
$stub->value = '';
106+
$stub->value = null;
105107
if (0 <= $maxItems && $maxItems <= $pos) {
106108
$stub->cut = count($a);
107-
$a = array();
109+
$a = null;
108110
}
109111
}
110112
if (empty($softRefs[$h])) {
111113
$softRefs[$h] = $stub;
112114
} else {
113115
$stub = $softRefs[$h];
114116
$stub->ref = ++$refs;
117+
$a = null;
115118
}
116119
break;
117120

@@ -120,23 +123,26 @@ protected function doClone($var)
120123
$stub = new Stub();
121124
$stub->type = Stub::TYPE_RESOURCE;
122125
$stub->class = $zval['resource_type'];
123-
$stub->value = $h;
124-
$a = $this->castResource($v, $stub, 0 < $i);
125-
if (Stub::TYPE_RESOURCE !== $stub->type) {
126-
break;
126+
$stub->value = $v;
127+
$a = $this->castResource($stub, 0 < $i);
128+
if ($v !== $stub->value) {
129+
if (Stub::TYPE_RESOURCE !== $stub->type) {
130+
break;
131+
}
132+
$h = (int) $stub->value;
127133
}
128-
$h = $stub->value;
129-
$stub->value = '';
134+
$stub->value = null;
130135
if (0 <= $maxItems && $maxItems <= $pos) {
131136
$stub->cut = count($a);
132-
$a = array();
137+
$a = null;
133138
}
134139
}
135140
if (empty($softRefs[$h])) {
136141
$softRefs[$h] = $stub;
137142
} else {
138143
$stub = $softRefs[$h];
139144
$stub->ref = ++$refs;
145+
$a = null;
140146
}
141147
break;
142148
}

src/Symfony/Component/VarDumper/Cloner/PhpCloner.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,26 @@ protected function doClone($var)
101101
$stub = new Stub();
102102
$stub->type = Stub::TYPE_OBJECT;
103103
$stub->class = get_class($v);
104-
$stub->value = $h;
105-
$a = $this->castObject($v, $stub, 0 < $i);
106-
if (Stub::TYPE_OBJECT !== $stub->type) {
107-
break;
104+
$stub->value = $v;
105+
$a = $this->castObject($stub, 0 < $i);
106+
if ($v !== $stub->value) {
107+
if (Stub::TYPE_OBJECT !== $stub->type) {
108+
break;
109+
}
110+
$h = spl_object_hash($stub->value);
108111
}
109-
$h = $stub->value;
110-
$stub->value = '';
112+
$stub->value = null;
111113
if (0 <= $maxItems && $maxItems <= $pos) {
112114
$stub->cut = count($a);
113-
$a = array();
115+
$a = null;
114116
}
115117
}
116118
if (empty($softRefs[$h])) {
117119
$softRefs[$h] = $stub;
118120
} else {
119121
$stub = $softRefs[$h];
120122
$stub->ref = ++$refs;
123+
$a = null;
121124
}
122125
break;
123126

@@ -127,23 +130,26 @@ protected function doClone($var)
127130
$stub = new Stub();
128131
$stub->type = Stub::TYPE_RESOURCE;
129132
$stub->class = get_resource_type($v);
130-
$stub->value = $h;
131-
$a = $this->castResource($v, $stub, 0 < $i);
132-
if (Stub::TYPE_RESOURCE !== $stub->type) {
133-
break;
133+
$stub->value = $v;
134+
$a = $this->castResource($stub, 0 < $i);
135+
if ($v !== $stub->value) {
136+
if (Stub::TYPE_RESOURCE !== $stub->type) {
137+
break;
138+
}
139+
$h = (int) $stub->value;
134140
}
135-
$h = $stub->value;
136-
$stub->value = '';
141+
$stub->value = null;
137142
if (0 <= $maxItems && $maxItems <= $pos) {
138143
$stub->cut = count($a);
139-
$a = array();
144+
$a = null;
140145
}
141146
}
142147
if (empty($softRefs[$h])) {
143148
$softRefs[$h] = $stub;
144149
} else {
145150
$stub = $softRefs[$h];
146151
$stub->ref = ++$refs;
152+
$a = null;
147153
}
148154
break;
149155
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function testGet()
4040
$out = ob_get_clean();
4141
$closureLabel = PHP_VERSION_ID >= 50400 ? 'public method' : 'function';
4242
$out = preg_replace('/[ \t]+$/m', '', $out);
43+
$intMax = PHP_INT_MAX;
4344

4445
$this->assertSame(
4546
<<<EOTXT
@@ -52,7 +53,7 @@ public function testGet()
5253
3 => NAN
5354
4 => INF
5455
5 => -INF
55-
6 => 9223372036854775807
56+
6 => {$intMax}
5657
"str" => "déjà"
5758
7 => b"é"
5859
"[]" => []

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function testGet()
4343
$closureLabel = PHP_VERSION_ID >= 50400 ? 'public method' : 'function';
4444
$out = preg_replace('/[ \t]+$/m', '', $out);
4545
$var['file'] = htmlspecialchars($var['file'], ENT_QUOTES, 'UTF-8');
46+
$intMax = PHP_INT_MAX;
4647

4748
$this->assertSame(
4849
<<<EOTXT
@@ -55,7 +56,7 @@ public function testGet()
5556
<span class=sf-dump-meta>3</span> => <span class=sf-dump-num>NAN</span>
5657
<span class=sf-dump-meta>4</span> => <span class=sf-dump-num>INF</span>
5758
<span class=sf-dump-meta>5</span> => <span class=sf-dump-num>-INF</span>
58-
<span class=sf-dump-meta>6</span> => <span class=sf-dump-num>9223372036854775807</span>
59+
<span class=sf-dump-meta>6</span> => <span class=sf-dump-num>{$intMax}</span>
5960
"<span class=sf-dump-meta>str</span>" => "<span class=sf-dump-str>déjà</span>"
6061
<span class=sf-dump-meta>7</span> => b"<span class=sf-dump-str>é</span>"
6162
"<span class=sf-dump-meta>[]</span>" => []

0 commit comments

Comments
 (0)
0