Skip to content

Commit 49c825e

Browse files
Merge branch '5.3' into 5.4
* 5.3: expand uninitialized session tests [Lock] Release PostgreSqlStore connection lock on failure [DomCrawler] Fix HTML5 parser charset option cs fix [HttpKernel] Do not attempt to register enum arguments in controller service locator [Mime] Fix missing sprintf in DkimSigner [Translation] [LocoProvider] Use rawurlencode and separate tag setting [Security] fix unserializing session payloads from v4 [Cache] Don't lock when doing nested computations [Messenger] fix Redis support on 32b arch [HttpFoundation] Fix notice when HTTP_PHP_AUTH_USER passed without pass [Security] Add getting started example to README
2 parents c4922fb + 81d0937 commit 49c825e

File tree

22 files changed

+389
-70
lines changed

22 files changed

+389
-70
lines changed

.appveyor.yml

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ install:
2121
- cd ext
2222
- appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php_apcu-5.1.19-7.2-ts-vc15-x86.zip
2323
- 7z x php_apcu-5.1.19-7.2-ts-vc15-x86.zip -y >nul
24+
- appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php_redis-5.3.2-7.2-ts-vc15-x86.zip
25+
- 7z x php_redis-5.3.2-7.2-ts-vc15-x86.zip -y >nul
2426
- cd ..
2527
- copy /Y php.ini-development php.ini-min
2628
- echo memory_limit=-1 >> php.ini-min
@@ -36,6 +38,7 @@ install:
3638
- echo opcache.enable_cli=1 >> php.ini-max
3739
- echo extension=php_openssl.dll >> php.ini-max
3840
- echo extension=php_apcu.dll >> php.ini-max
41+
- echo extension=php_redis.dll >> php.ini-max
3942
- echo apc.enable_cli=1 >> php.ini-max
4043
- echo extension=php_intl.dll >> php.ini-max
4144
- echo extension=php_mbstring.dll >> php.ini-max
@@ -54,6 +57,7 @@ install:
5457
- SET COMPOSER_ROOT_VERSION=%SYMFONY_VERSION%.x-dev
5558
- php composer.phar update --no-progress --ansi
5659
- php phpunit install
60+
- choco install memurai-developer
5761

5862
test_script:
5963
- SET X=0

.github/workflows/integration-tests.yml

-5
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,13 @@ jobs:
157157
- name: Run tests
158158
run: ./phpunit --group integration -v
159159
env:
160-
REDIS_HOST: localhost
161160
REDIS_CLUSTER_HOSTS: 'localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005'
162161
REDIS_SENTINEL_HOSTS: 'localhost:26379'
163162
REDIS_SENTINEL_SERVICE: redis_sentinel
164163
MESSENGER_REDIS_DSN: redis://127.0.0.1:7006/messages
165164
MESSENGER_AMQP_DSN: amqp://localhost/%2f/messages
166165
MESSENGER_SQS_DSN: "sqs://localhost:9494/messages?sslmode=disable&poll_timeout=0.01"
167166
MESSENGER_SQS_FIFO_QUEUE_DSN: "sqs://localhost:9494/messages.fifo?sslmode=disable&poll_timeout=0.01"
168-
MEMCACHED_HOST: localhost
169-
LDAP_HOST: localhost
170-
LDAP_PORT: 3389
171-
MONGODB_HOST: localhost
172167
KAFKA_BROKER: 127.0.0.1:9092
173168
POSTGRES_HOST: localhost
174169

phpunit.xml.dist

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<env name="LDAP_HOST" value="localhost" />
1919
<env name="LDAP_PORT" value="3389" />
2020
<env name="REDIS_HOST" value="localhost" />
21+
<env name="MESSENGER_REDIS_DSN" value="redis://localhost/messages" />
2122
<env name="MEMCACHED_HOST" value="localhost" />
2223
<env name="MONGODB_HOST" value="localhost" />
2324
<env name="ZOOKEEPER_HOST" value="localhost" />

src/Symfony/Component/Cache/LockRegistry.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static function compute(callable $callback, ItemInterface $item, bool &$s
9191

9292
$key = self::$files ? abs(crc32($item->getKey())) % \count(self::$files) : -1;
9393

94-
if ($key < 0 || (self::$lockedFiles[$key] ?? false) || !$lock = self::open($key)) {
94+
if ($key < 0 || self::$lockedFiles || !$lock = self::open($key)) {
9595
return $callback($item, $save);
9696
}
9797

src/Symfony/Component/DomCrawler/Crawler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ protected function sibling(\DOMNode $node, string $siblingDir = 'nextSibling')
11581158

11591159
private function parseHtml5(string $htmlContent, string $charset = 'UTF-8'): \DOMDocument
11601160
{
1161-
return $this->html5Parser->parse($this->convertToHtmlEntities($htmlContent, $charset), [], $charset);
1161+
return $this->html5Parser->parse($this->convertToHtmlEntities($htmlContent, $charset));
11621162
}
11631163

11641164
private function parseXhtml(string $htmlContent, string $charset = 'UTF-8'): \DOMDocument

src/Symfony/Component/HttpFoundation/ServerBag.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function getHeaders()
8989

9090
// PHP_AUTH_USER/PHP_AUTH_PW
9191
if (isset($headers['PHP_AUTH_USER'])) {
92-
$headers['AUTHORIZATION'] = 'Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.$headers['PHP_AUTH_PW']);
92+
$headers['AUTHORIZATION'] = 'Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.($headers['PHP_AUTH_PW'] ?? ''));
9393
} elseif (isset($headers['PHP_AUTH_DIGEST'])) {
9494
$headers['AUTHORIZATION'] = $headers['PHP_AUTH_DIGEST'];
9595
}

src/Symfony/Component/HttpFoundation/Tests/ServerBagTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ public function testHttpPasswordIsOptional()
5757
], $bag->getHeaders());
5858
}
5959

60+
public function testHttpPasswordIsOptionalWhenPassedWithHttpPrefix()
61+
{
62+
$bag = new ServerBag(['HTTP_PHP_AUTH_USER' => 'foo']);
63+
64+
$this->assertEquals([
65+
'AUTHORIZATION' => 'Basic '.base64_encode('foo:'),
66+
'PHP_AUTH_USER' => 'foo',
67+
], $bag->getHeaders());
68+
}
69+
6070
public function testHttpBasicAuthWithPhpCgi()
6171
{
6272
$bag = new ServerBag(['HTTP_AUTHORIZATION' => 'Basic '.base64_encode('foo:bar')]);

src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php

+5
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ public function process(ContainerBuilder $container)
140140
$type = ltrim($target = (string) ProxyHelper::getTypeHint($r, $p), '\\');
141141
$invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
142142

143+
if (is_subclass_of($type, \UnitEnum::class)) {
144+
// do not attempt to register enum typed arguments
145+
continue;
146+
}
147+
143148
if (isset($arguments[$r->name][$p->name])) {
144149
$target = $arguments[$r->name][$p->name];
145150
if ('?' !== $target[0]) {

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php

+27
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\DependencyInjection\ServiceLocator;
2525
use Symfony\Component\DependencyInjection\TypedReference;
2626
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
27+
use Symfony\Component\HttpKernel\Tests\Fixtures\Suit;
2728

2829
class RegisterControllerArgumentLocatorsPassTest extends TestCase
2930
{
@@ -400,6 +401,25 @@ public function testAlias()
400401
$this->assertEqualsCanonicalizing([RegisterTestController::class.'::fooAction', 'foo::fooAction'], array_keys($locator));
401402
}
402403

404+
/**
405+
* @requires PHP 8.1
406+
*/
407+
public function testEnumArgumentIsIgnored()
408+
{
409+
$container = new ContainerBuilder();
410+
$resolver = $container->register('argument_resolver.service')->addArgument([]);
411+
412+
$container->register('foo', NonNullableEnumArgumentWithDefaultController::class)
413+
->addTag('controller.service_arguments')
414+
;
415+
416+
$pass = new RegisterControllerArgumentLocatorsPass();
417+
$pass->process($container);
418+
419+
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
420+
$this->assertEmpty(array_keys($locator), 'enum typed argument is ignored');
421+
}
422+
403423
/**
404424
* @requires PHP 8
405425
*/
@@ -482,6 +502,13 @@ public function fooAction(string $someArg)
482502
}
483503
}
484504

505+
class NonNullableEnumArgumentWithDefaultController
506+
{
507+
public function fooAction(Suit $suit = Suit::Spades)
508+
{
509+
}
510+
}
511+
485512
class WithTarget
486513
{
487514
public function fooAction(

src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public function testSessionSaveAndResponseHasSessionCookie()
262262
$this->assertSame('123456', $cookies[0]->getValue());
263263
}
264264

265-
public function testUninitializedSession()
265+
public function testUninitializedSessionUsingInitializedSessionService()
266266
{
267267
$kernel = $this->createMock(HttpKernelInterface::class);
268268
$response = new Response();
@@ -283,6 +283,26 @@ public function testUninitializedSession()
283283
$this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER));
284284
}
285285

286+
public function testUninitializedSessionUsingSessionFromRequest()
287+
{
288+
$kernel = $this->createMock(HttpKernelInterface::class);
289+
$response = new Response();
290+
$response->setSharedMaxAge(60);
291+
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
292+
293+
$request = new Request();
294+
$request->setSession(new Session());
295+
296+
$listener = new SessionListener(new Container());
297+
$listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response));
298+
$this->assertFalse($response->headers->has('Expires'));
299+
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
300+
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
301+
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
302+
$this->assertSame('60', $response->headers->getCacheControlDirective('s-maxage'));
303+
$this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER));
304+
}
305+
286306
public function testUninitializedSessionWithoutInitializedSession()
287307
{
288308
$kernel = $this->createMock(HttpKernelInterface::class);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\Tests\Fixtures;
13+
14+
enum Suit: string
15+
{
16+
case Hearts = 'H';
17+
case Diamonds = 'D';
18+
case Clubs = 'C';
19+
case Spades = 'S';
20+
}

src/Symfony/Component/Lock/Store/PostgreSqlStore.php

+40-20
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,28 @@ public function save(Key $key)
9494
// prevent concurrency within the same connection
9595
$this->getInternalStore()->save($key);
9696

97-
$sql = 'SELECT pg_try_advisory_lock(:key)';
98-
$stmt = $this->getConnection()->prepare($sql);
99-
$stmt->bindValue(':key', $this->getHashedKey($key));
100-
$result = $stmt->execute();
97+
$lockAcquired = false;
10198

102-
// Check if lock is acquired
103-
if (true === $stmt->fetchColumn()) {
104-
$key->markUnserializable();
105-
// release sharedLock in case of promotion
106-
$this->unlockShared($key);
99+
try {
100+
$sql = 'SELECT pg_try_advisory_lock(:key)';
101+
$stmt = $this->getConnection()->prepare($sql);
102+
$stmt->bindValue(':key', $this->getHashedKey($key));
103+
$result = $stmt->execute();
107104

108-
return;
105+
// Check if lock is acquired
106+
if (true === $stmt->fetchColumn()) {
107+
$key->markUnserializable();
108+
// release sharedLock in case of promotion
109+
$this->unlockShared($key);
110+
111+
$lockAcquired = true;
112+
113+
return;
114+
}
115+
} finally {
116+
if (!$lockAcquired) {
117+
$this->getInternalStore()->delete($key);
118+
}
109119
}
110120

111121
throw new LockConflictedException();
@@ -122,19 +132,29 @@ public function saveRead(Key $key)
122132
// prevent concurrency within the same connection
123133
$this->getInternalStore()->saveRead($key);
124134

125-
$sql = 'SELECT pg_try_advisory_lock_shared(:key)';
126-
$stmt = $this->getConnection()->prepare($sql);
135+
$lockAcquired = false;
127136

128-
$stmt->bindValue(':key', $this->getHashedKey($key));
129-
$result = $stmt->execute();
137+
try {
138+
$sql = 'SELECT pg_try_advisory_lock_shared(:key)';
139+
$stmt = $this->getConnection()->prepare($sql);
140+
141+
$stmt->bindValue(':key', $this->getHashedKey($key));
142+
$result = $stmt->execute();
130143

131-
// Check if lock is acquired
132-
if (true === $stmt->fetchColumn()) {
133-
$key->markUnserializable();
134-
// release lock in case of demotion
135-
$this->unlock($key);
144+
// Check if lock is acquired
145+
if (true === $stmt->fetchColumn()) {
146+
$key->markUnserializable();
147+
// release lock in case of demotion
148+
$this->unlock($key);
136149

137-
return;
150+
$lockAcquired = true;
151+
152+
return;
153+
}
154+
} finally {
155+
if (!$lockAcquired) {
156+
$this->getInternalStore()->delete($key);
157+
}
138158
}
139159

140160
throw new LockConflictedException();

src/Symfony/Component/Lock/Tests/Store/PostgreSqlStoreTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Lock\Tests\Store;
1313

1414
use Symfony\Component\Lock\Exception\InvalidArgumentException;
15+
use Symfony\Component\Lock\Exception\LockConflictedException;
1516
use Symfony\Component\Lock\Key;
1617
use Symfony\Component\Lock\PersistingStoreInterface;
1718
use Symfony\Component\Lock\Store\PostgreSqlStore;
@@ -50,4 +51,31 @@ public function testInvalidDriver()
5051
$this->expectExceptionMessage('The adapter "Symfony\Component\Lock\Store\PostgreSqlStore" does not support');
5152
$store->exists(new Key('foo'));
5253
}
54+
55+
public function testSaveAfterConflict()
56+
{
57+
$store1 = $this->getStore();
58+
$store2 = $this->getStore();
59+
60+
$key = new Key(uniqid(__METHOD__, true));
61+
62+
$store1->save($key);
63+
$this->assertTrue($store1->exists($key));
64+
65+
$lockConflicted = false;
66+
67+
try {
68+
$store2->save($key);
69+
} catch (LockConflictedException $lockConflictedException) {
70+
$lockConflicted = true;
71+
}
72+
73+
$this->assertTrue($lockConflicted);
74+
$this->assertFalse($store2->exists($key));
75+
76+
$store1->delete($key);
77+
78+
$store2->save($key);
79+
$this->assertTrue($store2->exists($key));
80+
}
5381
}

0 commit comments

Comments
 (0)