8000 Merge branch '6.0' into 6.1 · symfony/symfony@bd72598 · GitHub
[go: up one dir, main page]

Skip to content

Commit bd72598

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: [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
2 parents f8ed3ce + 9115681 commit bd72598

File tree

10 files changed

+99
-15
lines changed

10 files changed

+99
-15
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ protected function configure()
5353
5454
Before running this command, the cache must be empty.
5555

56-
This command does not generate the classes cache (as when executing this
57-
command, too many classes that should be part of the cache are already loaded
58-
in memory). Use <comment>curl</comment> or any other similar tool to warm up
59-
the classes cache if you want.
60-
6156
EOF
6257
)
6358
;

src/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function pop(OutputFormatterStyleInterface $style = null): OutputFormatte
7777
/**
7878
* Computes current style with stacks top codes.
7979
*/
80-
public function getCurrent(): OutputFormatterStyle
80+
public function getCurrent(): OutputFormatterStyleInterface
8181
{
8282
if (empty($this->styles)) {
8383
return $this->emptyStyle;

src/Symfony/Component/HttpKernel/HttpKernel.php

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

73+
$this->requestStack->push($request);
7374
try {
7475
return $this->handleRaw($request, $type);
7576
} catch (\Exception $e) {
@@ -83,6 +84,8 @@ public function handle(Request $request, int $type = HttpKernelInterface::MAIN_R
8384
}
8485

8586
return $this->handleThrowable($e, $request, $type);
87+
} finally {
88+
$this->requestStack->pop();
8689
}
8790
}
8891

@@ -121,8 +124,6 @@ public function terminateWithException(\Throwable $exception, Request $request =
121124
*/
122125
private function handleRaw(Request $request, int $type = self::MAIN_REQUEST): Response
123126
{
124-
$this->requestStack->push($request);
125-
126127
// request
127128
$event = new RequestEvent($this, $request, $type);
128129
$this->dispatcher->dispatch($event, KernelEvents::REQUEST);
@@ -199,7 +200,6 @@ private function filterResponse(Response $response, Request $request, int $type)
199200
private function finishRequest(Request $request, int $type)
200201
{
201202
$this->dispatcher->dispatch(new FinishRequestEvent($this, $request, $type), KernelEvents::FINISH_REQUEST);
202-
$this->requestStack->pop();
203203
}
204204

205205
/**

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

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

43+
public function testRequestStackIsNotBrokenWhenControllerThrowsAnExceptionAndCatchIsTrue()
44+
{
45+
$requestStack = new RequestStack();
46+
$kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \RuntimeException(); }, $requestStack);
47+
48+
try {
49+
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
50+
} catch (\Throwable $exception) {
51+
}
52+
53+
self::assertNull($requestStack->getCurrentRequest());
54+
}
55+
56+
public function testRequestStackIsNotBrokenWhenControllerThrowsAnExceptionAndCatchIsFalse()
57+
{
58+
$requestStack = new RequestStack();
59+
$kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \RuntimeException(); }, $requestStack);
60+
61+
try {
62+
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false);
63+
} catch (\Throwable $exception) {
64+
}
65+
66+
self::assertNull($requestStack->getCurrentRequest());
67+
}
68+
69+
public function testRequestStackIsNotBrokenWhenControllerThrowsAnThrowable()
70+
{
71+
$requestStack = new RequestStack();
72+
$kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \Error(); }, $requestStack);
73+
74+
try {
75+
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
76+
} catch (\Throwable $exception) {
77+
}
78+
79+
self::assertNull($requestStack->getCurrentRequest());
80+
}
81+
4382
public function testHandleWhenControllerThrowsAnExceptionAndCatchIsFalseAndNoListenerIsRegistered()
4483
{
4584
$this->expectException(\RuntimeException::class);

src/Symfony/Component/Security/Http/RememberMe/RememberMeDetails.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ public function __construct(string $userFqcn, string $userIdentifier, int $expir
3737
public static function fromRawCookie(string $rawCookie): self
3838
{
3939
$cookieParts = explode(self::COOKIE_DELIMITER, base64_decode($rawCookie), 4);
40-
if (false === $cookieParts[1] = base64_decode($cookieParts[1], true)) {
41-
throw new AuthenticationException('The user identifier contains a character from outside the base64 alphabet.');
42-
}
4340
if (4 !== \count($cookieParts)) {
4441
throw new AuthenticationException('The cookie contains invalid data.');
4542
}
43+
if (false === $cookieParts[1] = base64_decode($cookieParts[1], true)) {
44+
throw new AuthenticationException('The user identifier contains a character from outside the base64 alphabet.');
45+
}
4646

4747
return new static(...$cookieParts);
4848
}

src/Symfony/Component/Security/Http/Tests/Authenticator/RememberMeAuthenticatorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,12 @@ public function testAuthenticateWithoutOldToken()
8989
$request = Request::create('/', 'GET', [], ['_remember_me_cookie' => base64_encode('foo:bar')]);
9090
$this->authenticator->authenticate($request);
9191
}
92+
93+
public function testAuthenticateWithTokenWithoutDelimiter()
94+
{
95+
$this->expectException(AuthenticationException::class);
96+
97+
$request = Request::create('/', 'GET', [], ['_remember_me_cookie' => 'invalid']);
98+
$this->authenticator->authenticate($request);
99+
}
92100
}

src/Symfony/Component/Serializer/Tests/Encoder/ChainDecoderTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ protected function setUp(): void
3737
[self::FORMAT_2, [], false],
3838
[self::FORMAT_3, [], false],
3939
[self::FORMAT_3, ['foo' => 'bar'], true],
40+
[self::FORMAT_3, ['foo' => 'bar2'], false],
4041
]);
4142

4243
$this->decoder2 = $this->createMock(DecoderInterface::class);
@@ -46,17 +47,35 @@ protected function setUp(): void
4647
[self::FORMAT_1, [], false],
4748
[self::FORMAT_2, [], true],
4849
[self::FORMAT_3, [], false],
50+
[self::FORMAT_3, ['foo' => 'bar'], false],
51+
[self::FORMAT_3, ['foo' => 'bar2'], true],
4952
]);
5053

5154
$this->chainDecoder = new ChainDecoder([$this->decoder1, $this->decoder2]);
5255
}
5356

5457
public function testSupportsDecoding()
5558
{
59+
$this->decoder1
60+
->method('decode')
61+
->willReturn('result1');
62+
$this->decoder2
63+
->method('decode')
64+
->willReturn('result2');
65+
5666
$this->assertTrue($this->chainDecoder->supportsDecoding(self::FORMAT_1));
67+
$this->assertEquals('result1', $this->chainDecoder->decode('', self::FORMAT_1, []));
68+
5769
$this->assertTrue($this->chainDecoder->supportsDecoding(self::FORMAT_2));
70+
$this->assertEquals('result2', $this->chainDecoder->decode('', self::FORMAT_2, []));
71+
5872
$this->assertFalse($this->chainDecoder->supportsDecoding(self::FORMAT_3));
73+
5974
$this->assertTrue($this->chainDecoder->supportsDecoding(self::FORMAT_3, ['foo' => 'bar']));
75+
$this->assertEquals('result1', $this->chainDecoder->decode('', self::FORMAT_3, ['foo' => 'bar']));
76+
77+
$this->assertTrue($this->chainDecoder->supportsDecoding(self::FORMAT_3, ['foo' => 'bar2']));
78+
$this->assertEquals('result2', $this->chainDecoder->decode('', self::FORMAT_3, ['foo' => 'bar2']));
6079
}
6180

6281
public function testDecode()

src/Symfony/Component/Serializer/Tests/Encoder/ChainEncoderTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected function setUp(): void
3939
[self::FORMAT_2, [], false],
4040
[self::FORMAT_3, [], false],
4141
[self::FORMAT_3, ['foo' => 'bar'], true],
42+
[self::FORMAT_3, ['foo' => 'bar2'], false],
4243
]);
4344

4445
$this->encoder2 = $this->createMock(EncoderInterface::class);
@@ -48,17 +49,35 @@ protected function setUp(): void
4849
[self::FORMAT_1, [], false],
4950
[self::FORMAT_2, [], true],
5051
[self::FORMAT_3, [], false],
52+
[self::FORMAT_3, ['foo' => 'bar'], false],
53+
[self::FORMAT_3, ['foo' => 'bar2'], true],
5154
]);
5255

5356
$this->chainEncoder = new ChainEncoder([$this->encoder1, $this->encoder2]);
5457
}
5558

5659
public function testSupportsEncoding()
5760
{
61+
$this->encoder1
62+
->method('encode')
63+
->willReturn('result1');
64+
$this->encoder2
65+
->method('encode')
66+
->willReturn('result2');
67+
5868
$this->assertTrue($this->chainEncoder->supportsEncoding(self::FORMAT_1));
69+
$this->assertEquals('result1', $this->chainEncoder->encode('', self::FORMAT_1, []));
70+
5971
$this->assertTrue($this->chainEncoder->supportsEncoding(self::FORMAT_2));
72+
$this->assertEquals('result2', $this->chainEncoder->encode('', self::FORMAT_2, []));
73+
6074
$this->assertFalse($this->chainEncoder->supportsEncoding(self::FORMAT_3));
75+
6176
$this->assertTrue($this->chainEncoder->supportsEncoding(self::FORMAT_3, ['foo' => 'bar']));
77+
$this->assertEquals('result1', $this->chainEncoder->encode('', self::FORMAT_3, ['foo' => 'bar']));
78+
79+
$this->assertTrue($this->chainEncoder->supportsEncoding(self::FORMAT_3, ['foo' => 'bar2']));
80+
$this->assertEquals('result2', $this->chainEncoder->encode('', self::FORMAT_3, ['foo' => 'bar2']));
6281
}
6382

6483
public function testEncode()

src/Symfony/Component/Translation/Bridge/Lokalise/LokaliseProvider.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,12 @@ public function delete(TranslatorBagInterface $translatorBag): void
120120
$keysIds = [];
121121

122122
foreach ($catalogue->getDomains() as $domain) {
123-
$keysToDelete = [];
124-
foreach (array_keys($catalogue->all($domain)) as $key) {
125-
$keysToDelete[] = $key;
123+
$keysToDelete = array_keys($catalogue->all($domain));
124+
125+
if (!$keysToDelete) {
126+
continue;
126127
}
128+
127129
$keysIds += $this->getKeysIds($keysToDelete, $domain);
128130
}
129131

src/Symfony/Component/Translation/Bridge/Lokalise/Tests/LokaliseProviderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,12 @@ public function testDeleteProcess()
699699
$translatorBag->addCatalogue(new MessageCatalogue('en', [
700700
'messages' => ['a' => 'trans_en_a'],
701701
'validators' => ['post.num_comments' => '{count, plural, one {# comment} other {# comments}}'],
702+
'domain_without_missing_messages' => [],
702703
]));
703704
$translatorBag->addCatalogue(new MessageCatalogue('fr', [
704705
'messages' => ['a' => 'trans_fr_a'],
705706
'validators' => ['post.num_comments' => '{count, plural, one {# commentaire} other {# commentaires}}'],
707+
'domain_without_missing_messages' => [],
706708
]));
707709

708710
$provider = $this->createProvider(

0 commit comments

Comments
 (0)
0