From 452bd0c56a185fca896e7ad6f30b2adb96358e1f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 24 Aug 2023 15:03:17 +0200 Subject: [PATCH] [VarDumper] Fix managing collapse state in CliDumper --- .../Component/VarDumper/Dumper/CliDumper.php | 3 ++ .../Tests/Caster/MysqliCasterTest.php | 1 - .../VarDumper/Tests/Dumper/CliDumperTest.php | 40 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/VarDumper/Dumper/CliDumper.php b/src/Symfony/Component/VarDumper/Dumper/CliDumper.php index b5d9ac3366bc8..690f6d016791b 100644 --- a/src/Symfony/Component/VarDumper/Dumper/CliDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/CliDumper.php @@ -128,6 +128,7 @@ public function setDisplayOptions(array $displayOptions) public function dumpScalar(Cursor $cursor, string $type, $value) { $this->dumpKey($cursor); + $this->collapseNextHash = $this->expandNextHash = false; $style = 'const'; $attr = $cursor->attr; @@ -191,6 +192,7 @@ public function dumpScalar(Cursor $cursor, string $type, $value) public function dumpString(Cursor $cursor, string $str, bool $bin, int $cut) { $this->dumpKey($cursor); + $this->collapseNextHash = $this->expandNextHash = false; $attr = $cursor->attr; if ($bin) { @@ -286,6 +288,7 @@ public function enterHash(Cursor $cursor, int $type, $class, bool $hasChild) } $this->dumpKey($cursor); + $this->expandNextHash = false; $attr = $cursor->attr; if ($this->collapseNextHash) { diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/MysqliCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/MysqliCasterTest.php index 983f541a3f786..4eba406efd325 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/MysqliCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/MysqliCasterTest.php @@ -30,7 +30,6 @@ public function testNotConnected() $xCast = <<assertSame($expectedOut, $out); } + public function testCollapse() + { + $stub = new Stub(); + $stub->type = Stub::TYPE_OBJECT; + $stub->class = 'stdClass'; + $stub->position = 1; + + $data = new Data([ + [ + $stub, + ], + [ + "\0~collapse=1\0foo" => 123, + "\0+\0bar" => [1 => 2], + ], + [ + 'bar' => 123, + ] + ]); + + $dumper = new CliDumper(); + $dump = $dumper->dump($data, true); + + $this->assertSame( + <<<'EOTXT' +{ + foo: 123 + +"bar": array:1 [ + "bar" => 123 + ] +} + +EOTXT + , + $dump + ); + } + private function getSpecialVars() { foreach (array_keys($GLOBALS) as $var) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy