Fix Invalid data in Session (#241)

Signed-off-by: Volodymyr Panivko <sveneld300@gmail.com>
This commit is contained in:
Volodymyr Panivko 2026-02-11 20:35:41 +01:00 • committed by GitHub
commit 8f8af90007
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View file

@ -171,6 +171,12 @@ class Session implements SessionInterface
return $this->data = [];
}
return $this->data = json_decode($rawData, true, flags: \JSON_THROW_ON_ERROR);
$decoded = json_decode($rawData, true, flags: \JSON_THROW_ON_ERROR);
if (!\is_array($decoded)) {
return $this->data = [];
}
return $this->data = $decoded;
}
}

View file

@ -33,4 +33,18 @@ class SessionTest extends TestCase
$result = $session->all();
$this->assertEquals(['foo' => 'bar'], $result);
}
public function testAllReturnsEmptyArrayForNullPayload()
{
$store = $this->getMockBuilder(InMemorySessionStore::class)
->disableOriginalConstructor()
->onlyMethods(['read'])
->getMock();
$store->expects($this->once())->method('read')->willReturn('null');
$session = new Session($store);
$result = $session->all();
$this->assertSame([], $result);
}
}