Skip to content

Commit 34dba9c

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: [LokaliseBridge] Fix push command --delete-missing options when there are no missing messages fix bad help message in cache warmup command [Console] Fix OutputFormatterStyleStack::getCurrent return type Count cookie parts before accessing the second Fix RequestStack state if throwable is thrown [Serializer] Fix caching context-aware encoders/decoders in ChainEncoder/ChainDecoder [Serializer] Revert deprecation of `ContextAwareEncoderInterface` and `ContextAwareDecoderInterface`
2 parents 7c4f2d0 + 9590a9b commit 34dba9c

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

HttpKernel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function handle(Request $request, int $type = HttpKernelInterface::MAIN_R
7272
{
7373
$request->headers->set('X-Php-Ob-Level', (string) ob_get_level());
7474

75+
$this->requestStack->push($request);
7576
try {
7677
return $this->handleRaw($request, $type);
7778
} catch (\Throwable $e) {
@@ -89,6 +90,8 @@ public function handle(Request $request, int $type = HttpKernelInterface::MAIN_R
8990
}
9091

9192
return $this->handleThrowable($e, $request, $type);
93+
} finally {
94+
$this->requestStack->pop();
9295
}
9396
}
9497

@@ -124,8 +127,6 @@ public function terminateWithException(\Throwable $exception, Request $request =
124127
*/
125128
private function handleRaw(Request $request, int $type = self::MAIN_REQUEST): Response
126129
{
127-
$this->requestStack->push($request);
128-
129130
// request
130131
$event = new RequestEvent($this, $request, $type);
131132
$this->dispatcher->dispatch($event, KernelEvents::REQUEST);
@@ -203,7 +204,6 @@ private function filterResponse(Response $response, Request $request, int $type)
203204
private function finishRequest(Request $request, int $type)
204205
{
205206
$this->dispatcher->dispatch(new FinishRequestEvent($this, $request, $type), KernelEvents::FINISH_REQUEST);
206-
$this->requestStack->pop();
207207
}
208208

209209
/**

Tests/HttpKernelTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,45 @@ public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue()
4545
$kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true);
4646
}
4747

48+
public function testRequestStackIsNotBrokenWhenControllerThrowsAnExceptionAndCatchIsTrue()
49+
{
50+
$requestStack = new RequestStack();
51+
$kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \RuntimeException(); }, $requestStack);
52+
53+
try {
54+
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
55+
} catch (\Throwable $exception) {
56+
}
57+
58+
self::assertNull($requestStack->getCurrentRequest());
59+
}
60+
61+
public function testRequestStackIsNotBrokenWhenControllerThrowsAnExceptionAndCatchIsFalse()
62+
{
63+
$requestStack = new RequestStack();
64+
$kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \RuntimeException(); }, $requestStack);
65+
66+
try {
67+
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false);
68+
} catch (\Throwable $exception) {
69+
}
70+
71+
self::assertNull($requestStack->getCurrentRequest());
72+
}
73+
74+
public function testRequestStackIsNotBrokenWhenControllerThrowsAnThrowable()
75+
{
76+
$requestStack = new RequestStack();
77+
$kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \Error(); }, $requestStack);
78+
79+
try {
80+
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
81+
} catch (\Throwable $exception) {
82+
}
83+
84+
self::assertNull($requestStack->getCurrentRequest());
85+
}
86+
4887
/**
4988
* Catch exceptions: false
5089
* Throwable type: RuntimeException

0 commit comments

Comments
 (0)