Fix Invalid data in Session (#241)
Signed-off-by: Volodymyr Panivko <sveneld300@gmail.com>
This commit is contained in:
parent
43e7a39a21
commit
8f8af90007
2 changed files with 21 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue