Skip to content

Commit bcc5b4b

Browse files
Merge branch '5.4' into 6.0
* 5.4: 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 4b7ef0e + 49c825e commit bcc5b4b

File tree

22 files changed

+373
-76
lines changed

22 files changed

+373
-76
lines changed

.appveyor.yml

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ install:
2222
- cd ext
2323
- appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php_apcu-5.1.21-8.0-ts-vs16-x86.zip
2424
- 7z x php_apcu-5.1.21-8.0-ts-vs16-x86.zip -y >nul
25+
- appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php_redis-5.3.5-8.0-ts-vs16-x86.zip
26+
- 7z x php_redis-5.3.5-8.0-ts-vs16-x86.zip -y >nul
2527
- cd ..
2628
- copy /Y php.ini-development php.ini-min
2729
- echo memory_limit=-1 >> php.ini-min
@@ -37,6 +39,7 @@ install:
3739
- echo opcache.enable_cli=1 >> php.ini-max
3840
- echo extension=php_openssl.dll >> php.ini-max
3941
- echo extension=php_apcu.dll >> php.ini-max
42+
- echo extension=php_redis.dll >> php.ini-max
4043
- echo apc.enable_cli=1 >> php.ini-max
4144
- echo extension=php_intl.dll >> php.ini-max
4245
- echo extension=php_mbstring.dll >> php.ini-max
@@ -55,6 +58,7 @@ install:
5558
- SET COMPOSER_ROOT_VERSION=%SYMFONY_VERSION%.x-dev
5659
- php composer.phar update --no-progress --ansi
5760
- php phpunit install
61+
- choco install memurai-developer
5862

5963
test_script:
6064
- 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
@@ -90,7 +90,7 @@ public static function compute(callable $callback, ItemInterface $item, bool &$s
9090

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

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

src/Symfony/Component/DomCrawler/Crawler.php

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

10541054
private function parseHtml5(string $htmlContent, string $charset = 'UTF-8'): \DOMDocument
10551055
{
1056-
return $this->html5Parser->parse($this->convertToHtmlEntities($htmlContent, $charset), [], $charset);
1056+
return $this->html5Parser->parse($this->convertToHtmlEntities($htmlContent, $charset));
10571057
}
10581058

10591059
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
@@ -87,7 +87,7 @@ public function getHeaders(): array
8787

8888
// PHP_AUTH_USER/PHP_AUTH_PW
8989
if (isset($headers['PHP_AUTH_USER'])) {
90-
$headers['AUTHORIZATION'] = 'Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.$headers['PHP_AUTH_PW']);
90+
$headers['AUTHORIZATION'] = 'Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.($headers['PHP_AUTH_PW'] ?? ''));
9191
} elseif (isset($headers['PHP_AUTH_DIGEST'])) {
9292
$headers['AUTHORIZATION'] = $headers['PHP_AUTH_DIGEST'];
9393
}

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
@@ -123,6 +123,11 @@ public function process(ContainerBuilder $container)
123123
$type = ltrim($target = (string) ProxyHelper::getTypeHint($r, $p), '\\');
124124
$invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
125125

126+
if (is_subclass_of($type, \UnitEnum::class)) {
127+
// do not attempt to register enum typed arguments
128+
continue;
129+
}
130+
126131
if (isset($arguments[$r->name][$p->name])) {
127132
$target = $arguments[$r->name][$p->name];
128133
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
public function testBindWithTarget()
404424
{
405425
$container = new ContainerBuilder();
@@ -479,6 +499,13 @@ public function fooAction(string $someArg)
479499
}
480500
}
481501

502+
class NonNullableEnumArgumentWithDefaultController
503+
{
504+
public function fooAction(Suit $suit = Suit::Spades)
505+
{
506+
}
507+
}
508+
482509
class WithTarget
483510
{
484511
public function fooAction(

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,18 @@ public function testSessionSaveAndResponseHasSessionCookie()
308308
$this->assertSame('123456', $cookies[0]->getValue());
309309
}
310310

311-
public function testUninitializedSession()
311+
public function testUninitializedSessionUsingSessionFromRequest()
312312
{
313313
$kernel = $this->createMock(HttpKernelInterface::class);
314314
$response = new Response();
315315
$response->setSharedMaxAge(60);
316316
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
317317

318-
$container = new Container();
318+
$request = new Request();
319+
$request->setSession(new Session());
319320

320-
$listener = new SessionListener($container);
321-
$listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, $response));
321+
$listener = new SessionListener(new Container());
322+
$listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response));
322323
$this->assertFalse($response->headers->has('Expires'));
323324
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
324325
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
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
@@ -72,18 +72,28 @@ public function save(Key $key)
7272
// prevent concurrency within the same connection
7373
$this->getInternalStore()->save($key);
7474

75-
$sql = 'SELECT pg_try_advisory_lock(:key)';
76-
$stmt = $this->getConnection()->prepare($sql);
77-
$stmt->bindValue(':key', $this->getHashedKey($key));
78-
$result = $stmt->execute();
75+
$lockAcquired = false;
7976

80-
// Check if lock is acquired
81-
if (true === $stmt->fetchColumn()) {
82-
$key->markUnserializable();
83-
// release sharedLock in case of promotion
84-
$this->unlockShared($key);
77+
try {
78+
$sql = 'SELECT pg_try_advisory_lock(:key)';
79+
$stmt = $this->getConnection()->prepare($sql);
80+
$stmt->bindValue(':key', $this->getHashedKey($key));
81+
$result = $stmt->execute();
8582

86-
return;
83+
// Check if lock is acquired
84+
if (true === $stmt->fetchColumn()) {
85+
$key->markUnserializable();
86+
// release sharedLock in case of promotion
87+
$this->unlockShared($key);
88+
89+
$lockAcquired = true;
90+
91+
return;
92+
}
93+
} finally {
94+
if (!$lockAcquired) {
95+
$this->getInternalStore()->delete($key);
96+
}
8797
}
8898

8999
throw new LockConflictedException();
@@ -94,19 +104,29 @@ public function saveRead(Key $key)
94104
// prevent concurrency within the same connection
95105
$this->getInternalStore()->saveRead($key);
96106

97-
$sql = 'SELECT pg_try_advisory_lock_shared(:key)';
98-
$stmt = $this->getConnection()->prepare($sql);
107+
$lockAcquired = false;
99108

100-
$stmt->bindValue(':key', $this->getHashedKey($key));
101-
$result = $stmt->execute();
109+
try {
110+
$sql = 'SELECT pg_try_advisory_lock_shared(:key)';
111+
$stmt = $this->getConnection()->prepare($sql);
112+
113+
$stmt->bindValue(':key', $this->getHashedKey($key));
114+
$result = $stmt->execute();
102115

103-
// Check if lock is acquired
104-
if (true === $stmt->fetchColumn()) {
105-
$key->markUnserializable();
106-
// release lock in case of demotion
107-
$this->unlock($key);
116+
// Check if lock is acquired
117+
if (true === $stmt->fetchColumn()) {
118+
$key->markUnserializable();
119+
// release lock in case of demotion
120+
$this->unlock($key);
108121

109-
return;
122+
$lockAcquired = true;
123+
124+
return;
125+
}
126+
} finally {
127+
if (!$lockAcquired) {
128+
$this->getInternalStore()->delete($key);
129+
}
110130
}
111131

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