Skip to content

Commit 2046d8c

Browse files
Merge branch '6.0' into 6.1
* 6.0: [Mailer] Include all transports' debug messages in RoundRobin transport exception [FrameworkBundle] fix: fix help message Use relative timestamps [Cache] Fix dealing with ext-redis' multi/exec returning a bool [Messenger][Amqp] Added missing rpc_timeout option [Serializer] Prevent GetSetMethodNormalizer from creating invalid magic method call [HttpFoundation] Fix dumping array cookies [WebProfilerBundle] Fix dump header not being displayed TraceableHttpClient: increase decorator's priority Use static methods inside data providers [FrameworkBundle] Allow configuring `framework.exceptions` with a config builder bug #48313 [Mime] Fix MessagePart serialization [ErrorHandler][DebugClassLoader] Fix some new return types support Fix getting the name of closures on PHP 8.1.11+ [Translator] Fix typo "internal" / "interval" fix dumping top-level tagged values
2 parents b54cce1 + 22fe17e commit 2046d8c

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,10 @@ public function __toString(): string
502502
$cookies = [];
503503

504504
foreach ($this->cookies as $k => $v) {
505-
$cookies[] = $k.'='.$v;
505+
$cookies[] = \is_array($v) ? http_build_query([$k => $v], '', '; ', \PHP_QUERY_RFC3986) : "$k=$v";
506506
}
507507

508-
if (!empty($cookies)) {
508+
if ($cookies) {
509509
$cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n";
510510
}
511511

Session/Storage/Handler/MemcachedSessionHandler.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ protected function doRead(string $sessionId): string
6969

7070
public function updateTimestamp(string $sessionId, string $data): bool
7171
{
72-
$ttl = ($this->ttl instanceof \Closure ? ($this->ttl)() : $this->ttl) ?? \ini_get('session.gc_maxlifetime');
73-
$this->memcached->touch($this->prefix.$sessionId, time() + (int) $ttl);
72+
$this->memcached->touch($this->prefix.$sessionId, $this->getCompatibleTtl());
7473

7574
return true;
7675
}
@@ -79,10 +78,21 @@ public function updateTimestamp(string $sessionId, string $data): bool
7978
* {@inheritdoc}
8079
*/
8180
protected function doWrite(string $sessionId, string $data): bool
81+
{
82+
return $this->memcached->set($this->prefix.$sessionId, $data, $this->getCompatibleTtl());
83+
}
84+
85+
private function getCompatibleTtl(): int
8286
{
8387
$ttl = ($this->ttl instanceof \Closure ? ($this->ttl)() : $this->ttl) ?? \ini_get('session.gc_maxlifetime');
8488

85-
return $this->memcached->set($this->prefix.$sessionId, $data, time() + (int) $ttl);
89+
// If the relative TTL that is used exceeds 30 days, memcached will treat the value as Unix time.
90+
// We have to convert it to an absolute Unix time at this point, to make sure the TTL is correct.
91+
if ($ttl > 60 * 60 * 24 * 30) {
92+
$ttl += time();
93+
}
94+
95+
return $ttl;
8696
}
8797

8898
/**

Tests/RequestTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,12 @@ public function testToString()
16991699
$asString = (string) $request;
17001700

17011701
$this->assertStringContainsString('Cookie: Foo=Bar; Another=Cookie', $asString);
1702+
1703+
$request->cookies->set('foo.bar', [1, 2]);
1704+
1705+
$asString = (string) $request;
1706+
1707+
$this->assertStringContainsString('foo.bar%5B0%5D=1; foo.bar%5B1%5D=2', $asString);
17021708
}
17031709

17041710
public function testIsMethod()

Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
/**
1818
* @requires extension memcached
19+
*
1920
* @group time-sensitive
2021
*/
2122
class MemcachedSessionHandlerTest extends TestCase
@@ -92,13 +93,30 @@ public function testWriteSession()
9293
$this->memcached
9394
->expects($this->once())
9495
->method('set')
95-
->with(self::PREFIX.'id', 'data', $this->equalTo(time() + self::TTL, 2))
96+
->with(self::PREFIX.'id', 'data', $this->equalTo(self::TTL, 2))
9697
->willReturn(true)
9798
;
9899

99100
$this->assertTrue($this->storage->write('id', 'data'));
100101
}
101102

103+
public function testWriteSessionWithLargeTTL()
104+
{
105+
$this->memcached
106+
->expects($this->once())
107+
->method('set')
108+
->with(self::PREFIX.'id', 'data', $this->equalTo(time() + self::TTL + 60 * 60 * 24 * 30, 2))
109+
->willReturn(true)
110+
;
111+
112+
$storage = new MemcachedSessionHandler(
113+
$this->memcached,
114+
['prefix' => self::PREFIX, 'expiretime' => self::TTL + 60 * 60 * 24 * 30]
115+
);
116+
117+
$this->assertTrue($storage->write('id', 'data'));
118+
}
119+
102120
public function testDestroySession()
103121
{
104122
$this->memcached

0 commit comments

Comments
 (0)