Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite4d6e7b

Browse files
krzycnicolas-grekas
authored andcommitted
[HttpKernel] Fix empty request stack when terminating with exception
1 parentc52b0ed commite4d6e7b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

‎src/Symfony/Component/HttpKernel/HttpKernel.php‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,17 @@ public function terminateWithException(\Throwable $exception, Request $request =
112112
throw$exception;
113113
}
114114

115-
$response =$this->handleThrowable($exception,$request,self::MASTER_REQUEST);
115+
if ($pop =$request !==$this->requestStack->getMasterRequest()) {
116+
$this->requestStack->push($request);
117+
}
118+
119+
try {
120+
$response =$this->handleThrowable($exception,$request,self::MASTER_REQUEST);
121+
}finally {
122+
if ($pop) {
123+
$this->requestStack->pop();
124+
}
125+
}
116126

117127
$response->sendHeaders();
118128
$response->sendContent();

‎src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
useSymfony\Component\HttpFoundation\Response;
2121
useSymfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
2222
useSymfony\Component\HttpKernel\Controller\ControllerResolverInterface;
23+
useSymfony\Component\HttpKernel\Event\ExceptionEvent;
2324
useSymfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
2425
useSymfony\Component\HttpKernel\Exception\BadRequestHttpException;
2526
useSymfony\Component\HttpKernel\Exception\ControllerDoesNotReturnResponseException;
@@ -340,6 +341,22 @@ public function testTerminate()
340341
$this->assertEquals($response,$capturedResponse);
341342
}
342343

344+
publicfunctiontestTerminateWithException()
345+
{
346+
$dispatcher =newEventDispatcher();
347+
$requestStack =newRequestStack();
348+
$kernel =$this->getHttpKernel($dispatcher,null,$requestStack);
349+
350+
$dispatcher->addListener(KernelEvents::EXCEPTION,function (ExceptionEvent$event)use (&$capturedRequest,$requestStack) {
351+
$capturedRequest =$requestStack->getCurrentRequest();
352+
$event->setResponse(newResponse());
353+
});
354+
355+
$kernel->terminateWithException(new \Exception('boo'),$request = Request::create('/'));
356+
$this->assertSame($request,$capturedRequest);
357+
$this->assertNull($requestStack->getCurrentRequest());
358+
}
359+
343360
publicfunctiontestVerifyRequestStackPushPopDuringHandle()
344361
{
345362
$request =newRequest();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp