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

Skip to content
8000

Commit 2765bbf

Browse files
Merge branch '5.4' into 6.0
* 5.4: [Serializer] Add missing types to FormErrorNormalizer [HttpFoundation] Fix deps minor #47299 [Console] fix expected command name order with mixed integer and string namespaces (xabbuh) [HttpFoundation] Fix tests on PHP 8.2 fix expected command name order with mixed integer and string namespaces [Serializer] Add missing types to BackedEnumNormalizer Do not send deleted session cookie twice in the response
2 parents 7eaefd2 + c571101 commit 2765bbf

File tree

11 files changed

+88
-9
lines changed

11 files changed

+88
-9
lines changed

src/Symfony/Component/Console/Descriptor/ApplicationDescription.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private function sortCommands(array $commands): array
127127
}
128128

129129
if ($namespacedCommands) {
130-
ksort($namespacedCommands);
130+
ksort($namespacedCommands, \SORT_STRING);
131131
foreach ($namespacedCommands as $key => $commandsSet) {
132132
ksort($commandsSet);
133133
$sortedCommands[$key] = $commandsSet;

src/Symfony/Component/Console/Tests/Descriptor/ApplicationDescriptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function getNamespacesProvider()
3636
return [
3737
[['_global'], ['foobar']],
3838
[['a', 'b'], ['b:foo', 'a:foo', 'b:bar']],
39-
[['_global', 'b', 'z', 22, 33], ['z:foo', '1', '33:foo', 'b:foo', '22:foo:bar']],
39+
[['_global', 22, 33, 'b', 'z'], ['z:foo', '1', '33:foo', 'b:foo', '22:foo:bar']],
4040
];
4141
}
4242
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
Array
3+
(
4+
[0] => Content-Type: text/plain; charset=utf-8
5+
[1] => Cache-Control: max-age=0, private, must-revalidate
6+
[2] => Cache-Control: max-age=0, must-revalidate, private
7+
[3] => Date: Sat, 12 Nov 1955 20:04:00 GMT
8+
[4] => Expires: %s, %d %s %d %d:%d:%d GMT
9+
[5] => Set-Cookie: PHPSESSID=deleted; expires=%s, %d-%s-%d %d:%d:%d GMT; Max-Age=%d; %s
10+
)
11+
shutdown
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\Container;
4+
use Symfony\Component\HttpFoundation\Request;
5+
use Symfony\Component\HttpFoundation\RequestStack;
6+
use Symfony\Component\HttpFoundation\Response;
7+
use Symfony\Component\HttpFoundation\Session\SessionFactory;
8+
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorageFactory;
9+
use Symfony\Component\HttpKernel\Event\RequestEvent;
10+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
11+
use Symfony\Component\HttpKernel\EventListener\SessionListener;
12+
use Symfony\Component\HttpKernel\HttpKernelInterface;
13+
14+
/** @var Response $r */
15+
$r = require __DIR__.'/common.inc';
16+
17+
$sessionId = 'vqd4dpbtst3af0k4sdl18nebkn';
18+
session_id($sessionId);
19+
$sessionName = session_name();
20+
$_COOKIE[$sessionName] = $sessionId;
21+
22+
$request = new Request();
23+
$request->cookies->set($sessionName, $sessionId);
24+
25+
$requestStack = new RequestStack();
26+
$requestStack->push($request);
27+
28+
$sessionFactory = new SessionFactory($requestStack, new NativeSessionStorageFactory());
29+
30+
$container = new Container();
31+
$container->set('request_stack', $requestStack);
32+
$container->set('session_factory', $sessionFactory);
33+
34+
$listener = new SessionListener($container);
35+
36+
$kernel = new class($r) implements HttpKernelInterface {
37+
/**
38+
* @var Response
39+
*/
40+
private $response;
41+
42+
public function __construct(Response $response)
43+
{
44+
$this->response = $response;
45+
}
46+
47+
public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Response
48+
{
49+
return $this->response;
50+
}
51+
};
52+
53+
$listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST));
54+
$session = $request->getSession();
55+
$session->set('foo', 'bar');
56+
$session->invalidate();
57+
58+
$listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $r));
59+
60+
$r->sendHeaders();

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function testSession($fixture)
4646
$context = ['http' => ['header' => "Cookie: sid=123abc\r\n"]];
4747
$context = stream_context_create($context);
4848
$result = file_get_contents(sprintf('http://localhost:8053/%s.php', $fixture), false, $context);
49+
$result = preg_replace_callback('/expires=[^;]++/', function ($m) { return str_replace('-', ' ', $m[0]); }, $result);
4950

5051
$this->assertStringEqualsFile(__DIR__.sprintf('/Fixtures/%s.expected', $fixture), $result);
5152
}

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/Fixtures/empty_destroys.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ Array
1212
(
1313
[0] => Content-Type: text/plain; charset=utf-8
1414
[1] => Cache-Control: max-age=10800, private, must-revalidate
15-
[2] => Set-Cookie: sid=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly
15+
[2] => Set-Cookie: sid=deleted; expires=Thu, 01 Jan 1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly
1616
)
1717
shutdown

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/Fixtures/storage.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ Array
1616
(
1717
[0] => Content-Type: text/plain; charset=utf-8
1818
[1] => Cache-Control: max-age=0, private, must-revalidate
19-
[2] => Set-Cookie: sid=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly
19+
[2] => Set-Cookie: sid=deleted; expires=Thu, 01 Jan 1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly
2020
)
2121
shutdown

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/Fixtures/with_cookie_and_session.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ Array
2020
[0] => Content-Type: text/plain; charset=utf-8
2121
[1] => Cache-Control: max-age=10800, private, must-revalidate
2222
[2] => Set-Cookie: abc=def
23-
[3] => Set-Cookie: sid=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly
23+
[3] => Set-Cookie: sid=deleted; expires=Thu, 01 Jan 1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly
2424
)
2525
shutdown

src/Symfony/Component/HttpFoundation/composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"require-dev": {
2424
"predis/predis": "~1.0",
2525
"symfony/cache": "^5.4|^6.0",
26+
"symfony/dependency-injection": "^5.4|^6.0",
27+
"symfony/http-kernel": "^5.4.12|^6.0.12|^6.1.4",
2628
"symfony/mime": "^5.4|^6.0",
2729
"symfony/expression-language": "^5.4|^6.0"
2830
},

src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ public function onKernelResponse(ResponseEvent $event)
153153

154154
$isSessionEmpty = ($session instanceof Session ? $session->isEmpty() : empty($session->all())) && empty($_SESSION); // checking $_SESSION to keep compatibility with native sessions
155155
if ($requestSessionCookieId && $isSessionEmpty) {
156+
// PHP internally sets the session cookie value to "deleted" when setcookie() is called with empty string $value argument
157+
// which happens in \Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler::destroy
158+
// when the session gets invalidated (for example on logout) so we must handle this case here too
159+
// otherwise we would send two Set-Cookie headers back with the response
160+
SessionUtils::popSessionCookie($sessionName, 'deleted');
156161
$response->headers->clearCookie(
157162
$sessionName,
158163
$sessionCookiePath,

src/Symfony/Component/Serializer/Normalizer/BackedEnumNormalizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class BackedEnumNormalizer implements NormalizerInterface, DenormalizerInt
2525
/**
2626
* {@inheritdoc}
2727
*/
28-
public function normalize($object, $format = null, array $context = []): int|string
28+
public function normalize(mixed $object, string $format = null, array $context = []): int|string
2929
{
3030
if (!$object instanceof \BackedEnum) {
3131
throw new InvalidArgumentException('The data must belong to a backed enumeration.');
@@ -37,7 +37,7 @@ public function normalize($object, $format = null, array $context = []): int|str
3737
/**
3838
* {@inheritdoc}
3939
*/
40-
public function supportsNormalization($data, $format = null): bool
40+
public function supportsNormalization($data, string $format = null): bool
4141
{
4242
return $data instanceof \BackedEnum;
4343
}
@@ -47,7 +47,7 @@ public function supportsNormalization($data, $format = null): bool
4747
*
4848
* @throws NotNormalizableValueException
4949
*/
50-
public function denormalize($data, $type, $format = null, array $context = []): mixed
50+
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
5151
{
5252
if (!is_subclass_of($type, \BackedEnum::class)) {
5353
throw new InvalidArgumentException('The data must belong to a backed enumeration.');
@@ -67,7 +67,7 @@ public function denormalize($data, $type, $format = null, array $context = []):
6767
/**
6868
* {@inheritdoc}
6969
*/
70-
public function supportsDenormalization($data, $type, $format = null): bool
70+
public function supportsDenormalization(mixed $data, string $type, string $format = null): bool
7171
{
7272
return is_subclass_of($type, \BackedEnum::class);
7373
}

0 commit comments

Comments
 (0)
0