Skip to content

Commit

Permalink
[11.x] Fix only number as session key will result in numbered session…
Browse files Browse the repository at this point in the history
… keys (#51611)

* fix: replace array merge with array replace on session store

* test: add only integer test case to load session from handler
  • Loading branch information
Katalam authored May 29, 2024
1 parent a79593d commit 97238d2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Session/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function start()
*/
protected function loadSession()
{
$this->attributes = array_merge($this->attributes, $this->readFromHandler());
$this->attributes = array_replace($this->attributes, $this->readFromHandler());

$this->marshalErrorBag();
}
Expand Down
4 changes: 3 additions & 1 deletion tests/Session/SessionStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ protected function tearDown(): void
public function testSessionIsLoadedFromHandler()
{
$session = $this->getSession();
$session->getHandler()->shouldReceive('read')->once()->with($this->getSessionId())->andReturn(serialize(['foo' => 'bar', 'bagged' => ['name' => 'taylor']]));
$session->getHandler()->shouldReceive('read')->once()->with($this->getSessionId())->andReturn(serialize(['foo' => 'bar', 'bagged' => ['name' => 'taylor'], '123' => 'bax']));
$session->start();

$this->assertSame('bar', $session->get('foo'));
$this->assertSame('bax', $session->get('123'));
$this->assertSame('baz', $session->get('bar', 'baz'));
$this->assertTrue($session->has('foo'));
$this->assertTrue($session->has('123'));
$this->assertFalse($session->has('bar'));
$this->assertTrue($session->isStarted());

Expand Down

0 comments on commit 97238d2

Please sign in to comment.