Skip to content

Commit 284f865

Browse files
committedApr 6, 2020
Merge branch '4.4' into 5.0
* 4.4: [PropertyAccess] fix tests [WebProfilerBundle] fix test remove assertions that can never be reached [PropertyAccess] Improve message of unitialized property in php 7.4 [HttpFoundation] Fixed session migration with custom cookie lifetime [HttpKernel][FrameworkBundle] fix compat with Debug component [Serializer] Remove unused variable Allow URL-encoded special characters in basic auth part of URLs [Serializer] Fix unitialized properties (from PHP 7.4.2) when serializing context for the cache key [Validator] Add missing Ukrainian and Russian translations Track session usage when setting the token [4.4][MonologBridge] Fix $level type No need to reconnect the bags to the session Support for Content Security Policy style-src-elem and script-src-elem in WebProfiler [PropertyInfo][ReflectionExtractor] Check the array mutator prefixes last when the property is singular [Security][Http][SwitchUserListener] Ignore all non existent username protection errors Add installation and minimal example to README
2 parents 26fb006 + 1055c11 commit 284f865

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed
 

‎Session/Storage/NativeSessionStorage.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,10 @@ public function regenerate(bool $destroy = false, int $lifetime = null)
215215
return false;
216216
}
217217

218-
if (null !== $lifetime) {
218+
if (null !== $lifetime && $lifetime != ini_get('session.cookie_lifetime')) {
219+
$this->save();
219220
ini_set('session.cookie_lifetime', $lifetime);
221+
$this->start();
220222
}
221223

222224
if ($destroy) {
@@ -225,10 +227,6 @@ public function regenerate(bool $destroy = false, int $lifetime = null)
225227

226228
$isRegenerated = session_regenerate_id($destroy);
227229

228-
// The reference to $_SESSION in session bags is lost in PHP7 and we need to re-create it.
229-
// @see https://bugs.php.net/70013
230-
$this->loadSession();
231-
232230
if (null !== $this->emulateSameSite) {
233231
$originalCookie = SessionUtils::popSessionCookie(session_name(), session_id());
234232
if (null !== $originalCookie) {

‎Tests/Session/Storage/NativeSessionStorageTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ public function testRegenerateDestroy()
120120
$this->assertEquals(11, $storage->getBag('attributes')->get('legs'));
121121
}
122122

123+
public function testRegenerateWithCustomLifetime()
124+
{
125+
$storage = $this->getStorage();
126+
$storage->start();
127+
$id = $storage->getId();
128+
$lifetime = 999999;
129+
$storage->getBag('attributes')->set('legs', 11);
130+
$storage->regenerate(false, $lifetime);
131+
$this->assertNotEquals($id, $storage->getId());
132+
$this->assertEquals(11, $storage->getBag('attributes')->get('legs'));
133+
$this->assertEquals($lifetime, ini_get('session.cookie_lifetime'));
134+
}
135+
123136
public function testSessionGlobalIsUpToDateAfterIdRegeneration()
124137
{
125138
$storage = $this->getStorage();

0 commit comments

Comments
 (0)
Please sign in to comment.