Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c542a03

Browse filesBrowse files
committed
Merge branch '4.4' into 5.4
* 4.4: [Validator] [Security] Add Norwegian translations add tests covering union types in MessengerPass [HttpFoundation] Prevent BinaryFileResponse::prepare from adding content type if no content is sent
2 parents 308edb5 + 43e5259 commit c542a03
Copy full SHA for c542a03

File tree

10 files changed

+186
-31
lines changed
Filter options

10 files changed

+186
-31
lines changed

‎src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/BinaryFileResponse.php
+40-31Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -206,22 +206,25 @@ public function setContentDisposition(string $disposition, string $filename = ''
206206
*/
207207
public function prepare(Request $request)
208208
{
209-
if (!$this->headers->has('Content-Type')) {
210-
$this->headers->set('Content-Type', $this->file->getMimeType() ?: 'application/octet-stream');
211-
}
209+
parent::prepare($request);
212210

213-
if ('HTTP/1.0' !== $request->server->get('SERVER_PROTOCOL')) {
214-
$this->setProtocolVersion('1.1');
211+
if ($this->isInformational() || $this->isEmpty()) {
212+
$this->maxlen = 0;
213+
214+
return $this;
215215
}
216216

217-
$this->ensureIEOverSSLCompatibility($request);
217+
if (!$this->headers->has('Content-Type')) {
218+
$this->headers->set('Content-Type', $this->file->getMimeType() ?: 'application/octet-stream');
219+
}
218220

219221
$this->offset = 0;
220222
$this->maxlen = -1;
221223

222224
if (false === $fileSize = $this->file->getSize()) {
223225
return $this;
224226
}
227+
$this->headers->remove('Transfer-Encoding');
225228
$this->headers->set('Content-Length', $fileSize);
226229

227230
if (!$this->headers->has('Accept-Ranges')) {
@@ -291,6 +294,10 @@ public function prepare(Request $request)
291294
}
292295
}
293296

297+
if ($request->isMethod('HEAD')) {
298+
$this->maxlen = 0;
299+
}
300+
294301
return $this;
295302
}
296303

@@ -312,40 +319,42 @@ private function hasValidIfRangeHeader(?string $header): bool
312319
*/
313320
public function sendContent()
314321
{
315-
if (!$this->isSuccessful()) {
316-
return parent::sendContent();
317-
}
322+
try {
323+
if (!$this->isSuccessful()) {
324+
return parent::sendContent();
325+
}
318326

319-
if (0 === $this->maxlen) {
320-
return $this;
321-
}
327+
if (0 === $this->maxlen) {
328+
return $this;
329+
}
322330

323-
$out = fopen('php://output', 'w');
324-
$file = fopen($this->file->getPathname(), 'r');
331+
$out = fopen('php://output', 'w');
332+
$file = fopen($this->file->getPathname(), 'r');
325333

326-
ignore_user_abort(true);
334+
ignore_user_abort(true);
327335

328-
if (0 !== $this->offset) {
329-
fseek($file, $this->offset);
330-
}
336+
if (0 !== $this->offset) {
337+
fseek($file, $this->offset);
338+
}
331339

332-
$length = $this->maxlen;
333-
while ($length && !feof($file)) {
334-
$read = ($length > $this->chunkSize) ? $this->chunkSize : $length;
335-
$length -= $read;
340+
$length = $this->maxlen;
341+
while ($length && !feof($file)) {
342+
$read = ($length > $this->chunkSize) ? $this->chunkSize : $length;
343+
$length -= $read;
336344

337-
stream_copy_to_stream($file, $out, $read);
345+
stream_copy_to_stream($file, $out, $read);
338346

339-
if (connection_aborted()) {
340-
break;
347+
if (connection_aborted()) {
348+
break;
349+
}
341350
}
342-
}
343351

344-
fclose($out);
345-
fclose($file);
346-
347-
if ($this->deleteFileAfterSend && is_file($this->file->getPathname())) {
348-
unlink($this->file->getPathname());
352+
fclose($out);
353+
fclose($file);
354+
} finally {
355+
if ($this->deleteFileAfterSend && is_file($this->file->getPathname())) {
356+
unlink($this->file->getPathname());
357+
}
349358
}
350359

351360
return $this;

‎src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,21 @@ public function testStream()
396396
$this->assertNull($response->headers->get('Content-Length'));
397397
}
398398

399+
public function testPrepareNotAddingContentTypeHeaderIfNoContentResponse()
400+
{
401+
$request = Request::create('/');
402+
$request->headers->set('If-Modified-Since', date('D, d M Y H:i:s').' GMT');
403+
404+
$response = new BinaryFileResponse(__DIR__.'/File/Fixtures/test.gif', 200, ['Content-Type' => 'application/octet-stream']);
405+
$response->setLastModified(new \DateTimeImmutable('-1 day'));
406+
$response->isNotModified($request);
407+
408+
$response->prepare($request);
409+
410+
$this->assertSame(BinaryFileResponse::HTTP_NOT_MODIFIED, $response->getStatusCode());
411+
$this->assertFalse($response->headers->has('Content-Type'));
412+
}
413+
399414
protected function provideResponse()
400415
{
401416
return new BinaryFileResponse(__DIR__.'/../README.md', 200, ['Content-Type' => 'application/octet-stream']);

‎src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,20 @@ private function guessHandledClasses(\ReflectionClass $handlerClass, string $ser
235235

236236
if ($type instanceof \ReflectionUnionType) {
237237
$types = [];
238+
$invalidTypes = [];
238239
foreach ($type->getTypes() as $type) {
239240
if (!$type->isBuiltin()) {
240241
$types[] = (string) $type;
242+
} else {
243+
$invalidTypes[] = (string) $type;
241244
}
242245
}
243246

244247
if ($types) {
245248
return $types;
246249
}
250+
251+
throw new RuntimeException(sprintf('Invalid handler service "%s": type-hint of argument "$%s" in method "%s::__invoke()" must be a class , "%s" given.', $serviceId, $parameters[0]->getName(), $handlerClass->getName(), implode('|', $invalidTypes)));
247252
}
248253

249254
if ($type->isBuiltin()) {

‎src/Symfony/Component/Messenger/Tests/DependencyInjection/MessengerPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/DependencyInjection/MessengerPassTest.php
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use Symfony\Component\Messenger\Middleware\HandleMessageMiddleware;
3939
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
4040
use Symfony\Component\Messenger\Middleware\StackInterface;
41+
use Symfony\Component\Messenger\Tests\Fixtures\ChildDummyMessage;
4142
use Symfony\Component\Messenger\Tests\Fixtures\DummyCommand;
4243
use Symfony\Component\Messenger\Tests\Fixtures\DummyCommandHandler;
4344
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
@@ -47,6 +48,8 @@
4748
use Symfony\Component\Messenger\Tests\Fixtures\MultipleBusesMessageHandler;
4849
use Symfony\Component\Messenger\Tests\Fixtures\SecondMessage;
4950
use Symfony\Component\Messenger\Tests\Fixtures\TaggedDummyHandler;
51+
use Symfony\Component\Messenger\Tests\Fixtures\UnionBuiltinTypeArgumentHandler;
52+
use Symfony\Component\Messenger\Tests\Fixtures\UnionTypeArgumentHandler;
5053
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface;
5154

5255
class MessengerPassTest extends TestCase
@@ -540,6 +543,43 @@ public function testBuiltinArgumentTypeHandler()
540543
(new MessengerPass())->process($container);
541544
}
542545

546+
/**
547+
* @requires PHP 8
548+
*/
549+
public function testUnionTypeArgumentsTypeHandler()
550+
{
551+
$container = $this->getContainerBuilder($busId = 'message_bus');
552+
$container
553+
->register(UnionTypeArgumentHandler::class, UnionTypeArgumentHandler::class)
554+
->addTag('messenger.message_handler')
555+
;
556+
557+
(new MessengerPass())->process($container);
558+
559+
$handlersMapping = $container->getDefinition($busId.'.messenger.handlers_locator')->getArgument(0);
560+
561+
$this->assertArrayHasKey(ChildDummyMessage::class, $handlersMapping);
562+
$this->assertArrayHasKey(DummyMessage::class, $handlersMapping);
563+
$this->assertHandlerDescriptor($container, $handlersMapping, ChildDummyMessage::class, [UnionTypeArgumentHandler::class]);
564+
$this->assertHandlerDescriptor($container, $handlersMapping, DummyMessage::class, [UnionTypeArgumentHandler::class]);
565+
}
566+
567+
/**
568+
* @requires PHP 8
569+
*/
570+
public function testUnionBuiltinArgumentTypeHandler()
571+
{
572+
$this->expectException(RuntimeException::class);
573+
$this->expectExceptionMessage(sprintf('Invalid handler service "%s": type-hint of argument "$message" in method "%s::__invoke()" must be a class , "string|int" given.', UnionBuiltinTypeArgumentHandler::class, UnionBuiltinTypeArgumentHandler::class));
574+
$container = $this->getContainerBuilder();
575+
$container
576+
->register(UnionBuiltinTypeArgumentHandler::class, UnionBuiltinTypeArgumentHandler::class)
577+
->addTag('messenger.message_handler')
578+
;
579+
580+
(new MessengerPass())->process($container);
581+
}
582+
543583
public function testNeedsToHandleAtLeastOneMessage()
544584
{
545585
$this->expectException(RuntimeException::class);
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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\Messenger\Tests\Fixtures;
13+
14+
class UnionBuiltinTypeArgumentHandler
15+
{
16+
public function __invoke(string|int $message): void
17+
{
18+
}
19+
}
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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\Messenger\Tests\Fixtures;
13+
14+
class UnionTypeArgumentHandler
15+
{
16+
public function __invoke(ChildDummyMessage|DummyMessage $message): void
17+
{
18+
}
19+
}

‎src/Symfony/Component/Security/Core/Resources/translations/security.nb.xlf

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Resources/translations/security.nb.xlf
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@
7070
<source>Invalid or expired login link.</source>
7171
<target>Ugyldig eller utløpt påloggingskobling.</target>
7272
</trans-unit>
73+
<trans-unit id="19">
74+
<source>Too many failed login attempts, please try again in %minutes% minute.</source>
75+
<target>For mange mislykkede påloggingsforsøk, prøv igjen om %minutes% minutt.</target>
76+
</trans-unit>
77+
<trans-unit id="20">
78+
<source>Too many failed login attempts, please try again in %minutes% minutes.</source>
79+
<target>For mange mislykkede påloggingsforsøk, prøv igjen om %minutes% minutter.</target>
80+
</trans-unit>
7381
</body>
7482
</file>
7583
</xliff>

‎src/Symfony/Component/Security/Core/Resources/translations/security.no.xlf

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Resources/translations/security.no.xlf
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@
7070
<source>Invalid or expired login link.</source>
7171
<target>Ugyldig eller utløpt påloggingskobling.</target>
7272
</trans-unit>
73+
<trans-unit id="19">
74+
<source>Too many failed login attempts, please try again in %minutes% minute.</source>
75+
<target>For mange mislykkede påloggingsforsøk, prøv igjen om %minutes% minutt.</target>
76+
</trans-unit>
77+
<trans-unit id="20">
78+
<source>Too many failed login attempts, please try again in %minutes% minutes.</source>
79+
<target>For mange mislykkede påloggingsforsøk, prøv igjen om %minutes% minutter.</target>
80+
</trans-unit>
7381
</body>
7482
</file>
7583
</xliff>

‎src/Symfony/Component/Validator/Resources/translations/validators.nb.xlf

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Resources/translations/validators.nb.xlf
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,22 @@
386386
<source>This value is not a valid International Securities Identification Number (ISIN).</source>
387387
<target>Denne verdien er ikke et gyldig International Securities Identification Number (ISIN).</target>
388388
</trans-unit>
389+
<trans-unit id="100">
390+
<source>This value should be a valid expression.</source>
391+
<target>Denne verdien skal være et gyldig uttrykk.</target>
392+
</trans-unit>
393+
<trans-unit id="101">
394+
<source>This value is not a valid CSS color.</source>
395+
<target>Denne verdien er ikke en gyldig CSS-farge.</target>
396+
</trans-unit>
397+
<trans-unit id="102">
398+
<source>This value is not a valid CIDR notation.</source>
399+
<target>Denne verdien er ikke en gyldig CIDR-notasjon.</target>
400+
</trans-unit>
401+
<trans-unit id="103">
402+
<source>The value of the netmask should be between {{ min }} and {{ max }}.</source>
403+
<target>Verdien på nettmasken skal være mellom {{ min }} og {{ max }}.</target>
404+
</trans-unit>
389405
</body>
390406
</file>
391407
</xliff>

‎src/Symfony/Component/Validator/Resources/translations/validators.no.xlf

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Resources/translations/validators.no.xlf
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,22 @@
386386
<source>This value is not a valid International Securities Identification Number (ISIN).</source>
387387
<target>Denne verdien er ikke et gyldig International Securities Identification Number (ISIN).</target>
388388
</trans-unit>
389+
<trans-unit id="100">
390+
<source>This value should be a valid expression.</source>
391+
<target>Denne verdien skal være et gyldig uttrykk.</target>
392+
</trans-unit>
393+
<trans-unit id="101">
394+
<source>This value is not a valid CSS color.</source>
395+
<target>Denne verdien er ikke en gyldig CSS-farge.</target>
396+
</trans-unit>
397+
<trans-unit id="102">
398+
<source>This value is not a valid CIDR notation.</source>
399+
<target>Denne verdien er ikke en gyldig CIDR-notasjon.</target>
400+
</trans-unit>
401+
<trans-unit id="103">
402+
<source>The value of the netmask should be between {{ min }} and {{ max }}.</source>
403+
<target>Verdien på nettmasken skal være mellom {{ min }} og {{ max }}.</target>
404+
</trans-unit>
389405
</body>
390406
</file>
391407
</xliff>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.