Skip to content

Commit

Permalink
SerializePlugin: Fix null parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jnvsor committed Aug 23, 2024
1 parent 858e591 commit c534c9e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Binary file modified build/kint.phar
Binary file not shown.
4 changes: 3 additions & 1 deletion src/Parser/SerializePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ public function parse(&$var, Value &$o, int $trigger): void

$options = ['allowed_classes' => self::$allowed_classes];

$ran = false;
if (!self::$safe_mode || !\in_array($trimmed[0], ['C', 'O', 'a'], true)) {
// Suppress warnings on unserializeable variable
$data = @\unserialize($trimmed, $options);
$ran = true;

if (false === $data && 'b:0;' !== \substr($trimmed, 0, 4)) {
return;
Expand All @@ -94,7 +96,7 @@ public function parse(&$var, Value &$o, int $trigger): void

$r = new Representation('Serialized');

if (isset($data)) {
if ($ran) {
$r->contents = $this->getParser()->parse($data, $base_obj);
} else {
$base_obj->hints[] = 'blacklist';
Expand Down
6 changes: 5 additions & 1 deletion tests/Parser/SerializePluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ public function testParse()
$b = new Value('$v');
$b->access_path = '$v';

$v = \serialize(['obj' => $p]);
$v = \serialize(null);
$obj = $p->parse($v, clone $b);
$this->assertSame($v, $obj->value->contents);

$p->addPlugin(new SerializePlugin($p));

$obj = $p->parse($v, clone $b);
$this->assertSame('null', $obj->getRepresentation('serialized')->contents->type);

$v = \serialize(['obj' => $p]);
$obj = $p->parse($v, clone $b);
$this->assertContains('blacklist', $obj->getRepresentation('serialized')->contents->hints);

Expand Down

0 comments on commit c534c9e

Please sign in to comment.