Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 22aa620

Browse files
committed
bug #18954 [3.1][HttpKernel] Fix RequestDataCollector starting the session (romainneutron)
This PR was merged into the 3.1 branch. Discussion ---------- [3.1][HttpKernel] Fix RequestDataCollector starting the session | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18951 | License | MIT The RequestDataCollector starts a non-started session on kernel response. This produces bug #18951 I'm not sure if this is the right fix, let's discuss it. Commits ------- ab62dcf [HttpKernel] Fix RequestDataCollector starting the session
2 parents eced97b + ab62dcf commit 22aa620

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function collect(Request $request, Response $response, \Exception $except
130130
unset($this->controllers[$request]);
131131
}
132132

133-
if (null !== $session) {
133+
if (null !== $session && $session->isStarted()) {
134134
if ($request->attributes->has('_redirected')) {
135135
$this->data['redirect'] = $session->remove('sf_redirect');
136136
}
@@ -291,7 +291,7 @@ public function onKernelController(FilterControllerEvent $event)
291291

292292
public function onKernelResponse(FilterResponseEvent $event)
293293
{
294-
if (!$event->isMasterRequest() || !$event->getRequest()->hasSession()) {
294+
if (!$event->isMasterRequest() || !$event->getRequest()->hasSession() || !$event->getRequest()->getSession()->isStarted()) {
295295
return;
296296
}
297297

src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111

1212
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
1313

14+
use Symfony\Component\HttpFoundation\Session\Session;
15+
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
1416
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
17+
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
1518
use Symfony\Component\HttpKernel\HttpKernel;
1619
use Symfony\Component\HttpKernel\HttpKernelInterface;
1720
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
@@ -52,6 +55,20 @@ public function testCollect()
5255
$this->assertSame('application/json', $c->getContentType());
5356
}
5457

58+
public function testKernelResponseDoesNotStartSession()
59+
{
60+
$kernel = $this->getMock(HttpKernelInterface::class);
61+
$request = new Request();
62+
$session = new Session(new MockArraySessionStorage());
63+
$request->setSession($session);
64+
$response = new Response();
65+
66+
$c = new RequestDataCollector();
67+
$c->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response));
68+
69+
$this->assertFalse($session->isStarted());
70+
}
71+
5572
/**
5673
* Test various types of controller callables.
5774
*/

0 commit comments

Comments
 (0)