Skip to content

Commit ddf4dd3

Browse files
Merge branch '6.1' into 6.2
* 6.1: [Mailer] Include all transports' debug messages in RoundRobin transport exception [FrameworkBundle] fix: fix help message Fix HtmlSanitizer default configuration behavior for allowed schemes 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 [HttpKernel][ErrorHandler] Fix reading the SYMFONY_IDE env var [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 [Console] Fix clear line with question in section
2 parents b30304b + 2046d8c commit ddf4dd3

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ 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

508508
if ($cookies) {

Session/Storage/Handler/MemcachedSessionHandler.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,27 @@ protected function doRead(string $sessionId): string
6666

6767
public function updateTimestamp(string $sessionId, string $data): bool
6868
{
69-
$ttl = ($this->ttl instanceof \Closure ? ($this->ttl)() : $this->ttl) ?? \ini_get('session.gc_maxlifetime');
70-
$this->memcached->touch($this->prefix.$sessionId, time() + (int) $ttl);
69+
$this->memcached->touch($this->prefix.$sessionId, $this->getCompatibleTtl());
7170

7271
return true;
7372
}
7473

7574
protected function doWrite(string $sessionId, string $data): bool
75+
{
76+
return $this->memcached->set($this->prefix.$sessionId, $data, $this->getCompatibleTtl());
77+
}
78+
79+
private function getCompatibleTtl(): int
7680
{
7781
$ttl = ($this->ttl instanceof \Closure ? ($this->ttl)() : $this->ttl) ?? \ini_get('session.gc_maxlifetime');
7882

79-
return $this->memcached->set($this->prefix.$sessionId, $data, time() + (int) $ttl);
83+
// If the relative TTL that is used exceeds 30 days, memcached will treat the value as Unix time.
84+
// We have to convert it to an absolute Unix time at this point, to make sure the TTL is correct.
85+
if ($ttl > 60 * 60 * 24 * 30) {
86+
$ttl += time();
87+
}
88+
89+
return $ttl;
8090
}
8191

8292
protected function doDestroy(string $sessionId): bool

Tests/RequestTest.php

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

17231723
$this->assertStringContainsString('Cookie: Foo=Bar; Another=Cookie', $asString);
1724+
1725+
$request->cookies->set('foo.bar', [1, 2]);
1726+
1727+
$asString = (string) $request;
1728+
1729+
$this->assertStringContainsString('foo.bar%5B0%5D=1; foo.bar%5B1%5D=2', $asString);
17241730
}
17251731

17261732
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)