Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a989491

Browse filesBrowse files
[VarDumper] Various minor fixes & cleanups
1 parent e4b48bb commit a989491
Copy full SHA for a989491

File tree

5 files changed

+22
-11
lines changed
Filter options

5 files changed

+22
-11
lines changed

‎src/Symfony/Bridge/Twig/Extension/DumpExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Extension/DumpExtension.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function dump(\Twig_Environment $env, $context)
6767
}
6868

6969
$dump = fopen('php://memory', 'r+b');
70-
$dumper = new HtmlDumper($dump);
70+
$dumper = new HtmlDumper($dump, $env->getCharset());
7171

7272
foreach ($vars as $value) {
7373
$dumper->dump($this->cloner->cloneVar($value));

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ public function serialize()
170170
return 'a:0:{}';
171171
}
172172

173+
$this->data[] = $this->fileLinkFormat;
174+
$this->data[] = $this->charset;
173175
$ser = serialize($this->data);
174176
$this->data = array();
175177
$this->dataCount = 0;
@@ -184,8 +186,10 @@ public function serialize()
184186
public function unserialize($data)
185187
{
186188
parent::unserialize($data);
189+
$charset = array_pop($this->data);
190+
$fileLinkFormat = array_pop($this->data);
187191
$this->dataCount = count($this->data);
188-
self::__construct($this->stopwatch);
192+
self::__construct($this->stopwatch, $fileLinkFormat, $charset);
189193
}
190194

191195
public function getDumpsCount()

‎src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public function testDump()
4949
);
5050
$this->assertSame($xDump, $dump);
5151

52-
$this->assertStringMatchesFormat('a:1:{i:0;a:5:{s:4:"data";O:39:"Symfony\Component\VarDumper\Cloner\Data":%a', $collector->serialize());
52+
$this->assertStringMatchesFormat('a:3:{i:0;a:5:{s:4:"data";O:39:"Symfony\Component\VarDumper\Cloner\Data":%a', $collector->serialize());
5353
$this->assertSame(0, $collector->getDumpsCount());
54-
$this->assertSame('a:0:{}', $collector->serialize());
54+
$this->assertSame('a:2:{i:0;b:0;i:1;s:5:"UTF-8";}', $collector->serialize());
5555
}
5656

5757
public function testCollectDefault()

‎src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@ public function setOutput($output)
8282
public function setCharset($charset)
8383
{
8484
$prev = $this->charset;
85-
$this->charsetConverter = 'fallback';
86-
8785
$charset = strtoupper($charset);
8886
$charset = null === $charset || 'UTF-8' === $charset || 'UTF8' === $charset ? 'CP1252' : $charset;
8987

88+
if ($prev === $charset) {
89+
return $prev;
90+
}
91+
$this->charsetConverter = 'fallback';
9092
$supported = true;
9193
set_error_handler(function () use (&$supported) {$supported = false;});
9294

‎src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ protected function style($style, $value, $attr = array())
362362
return '';
363363
}
364364

365-
$v = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
365+
$v = esc($value);
366366

367367
if ('ref' === $style) {
368368
if (empty($attr['count'])) {
@@ -373,18 +373,18 @@ protected function style($style, $value, $attr = array())
373373
return sprintf('<a class=sf-dump-ref href=#%s-ref%s title="%d occurrences">%s</a>', $this->dumpId, $r, 1 + $attr['count'], $v);
374374
}
375375

376-
if ('const' === $style && array_key_exists('value', $attr)) {
377-
$style .= sprintf(' title="%s"', htmlspecialchars(json_encode($attr['value']), ENT_QUOTES, 'UTF-8'));
376+
if ('const' === $style && isset($attr['value'])) {
377+
$style .= sprintf(' title="%s"', esc(is_scalar($attr['value']) ? $attr['value'] : json_encode($attr['value'])));
378378
} elseif ('public' === $style) {
379379
$style .= sprintf(' title="%s"', empty($attr['dynamic']) ? 'Public property' : 'Runtime added dynamic property');
380380
} elseif ('str' === $style && 1 < $attr['length']) {
381-
$style .= sprintf(' title="%s%s characters"', $attr['length'], $attr['binary'] ? ' binary or non-UTF-8' : '');
381+
$style .= sprintf(' title="%d%s characters"', $attr['length'], $attr['binary'] ? ' binary or non-UTF-8' : '');
382382
} elseif ('note' === $style && false !== $c = strrpos($v, '\\')) {
383383
return sprintf('<abbr title="%s" class=sf-dump-%s>%s</abbr>', $v, $style, substr($v, $c + 1));
384384
} elseif ('protected' === $style) {
385385
$style .= ' title="Protected property"';
386386
} elseif ('private' === $style) {
387-
$style .= sprintf(' title="Private property defined in class:&#10;`%s`"', $attr['class']);
387+
$style .= sprintf(' title="Private property defined in class:&#10;`%s`"', esc($attr['class']));
388388
}
389389

390390
$map = static::$controlCharsMap;
@@ -461,3 +461,8 @@ function ($m) {
461461
AbstractDumper::dumpLine($depth);
462462
}
463463
}
464+
465+
function esc($str)
466+
{
467+
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
468+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.