From 7473c422ee4170eeaa8f9a9ee6effbe608dad166 Mon Sep 17 00:00:00 2001 From: bscheshirwork Date: Sat, 24 Feb 2018 01:03:27 +0300 Subject: [PATCH] Fixes #15318: Fixed "session_name(): Cannot change session name when session is active" errors --- framework/CHANGELOG.md | 1 + framework/web/Session.php | 2 ++ tests/framework/web/session/SessionTest.php | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 055df82ef6..a5f43830e1 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -8,6 +8,7 @@ Yii Framework 2 Change Log - Bug #15692: Fix ExistValidator with targetRelation ignores filter (developeruz) - Bug #15693: Fixed `yii\filters\auth\HttpHeaderAuth` to work correctly when pattern is set but was not matched (bboure) - Bug #15696: Fix magic getter for ActiveRecord (developeruz) +- Bug #15318: Fixed "session_name(): Cannot change session name when session is active" errors (bscheshirwork, samdark) - Bug #15726: Fix ExistValidator is broken for NOSQL (developeruz) - Enh #15716: Implemented `\Traversable` in `yii\db\ArrayExpression` (silverfire) - Bug #15678: Fixed `resetForm()` method in `yii.activeForm.js` which used an undefined variable (Izumi-kun) diff --git a/framework/web/Session.php b/framework/web/Session.php index 999e7f91a7..16584ddac6 100644 --- a/framework/web/Session.php +++ b/framework/web/Session.php @@ -322,7 +322,9 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co */ public function setName($value) { + $this->freeze(); session_name($value); + $this->unfreeze(); } /** diff --git a/tests/framework/web/session/SessionTest.php b/tests/framework/web/session/SessionTest.php index a75a250333..28fc1e10d1 100644 --- a/tests/framework/web/session/SessionTest.php +++ b/tests/framework/web/session/SessionTest.php @@ -70,4 +70,22 @@ class SessionTest extends TestCase $this->assertNotEquals($oldGcProbability, $newGcProbability); $this->assertEquals(100, $newGcProbability); } + + /** + * Test set name. Also check set name twice and after open + */ + public function testSetName() + { + $session = new Session(); + $session->setName('oldName'); + + $this->assertEquals('oldName', $session->getName()); + + $session->open(); + $session->setName('newName'); + + $this->assertEquals('newName', $session->getName()); + + $session->destroy(); + } }