10000 Merge branch '4.4' into 5.4 · symfony/symfony@d5c67ce · GitHub
[go: up one dir, main page]

Skip to content

Commit d5c67ce

Browse files
committed
Merge branch '4.4' into 5.4
* 4.4: [Mime] Fix invalid DKIM signature with multiple parts Fix Command::run phpdoc Update Response.php [HttpFoundation] Fix TypeError on null `$_SESSION` in `NativeSessionStorage::save()`
2 parents 1b57d28 + 6467fa4 commit d5c67ce

File tree

6 files changed

+46
-3
lines changed

6 files changed

+46
-3
lines changed

src/Symfony/Component/Console/Command/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
242242
*
243243
* @return int The command exit code
244244
*
245-
* @throws \Exception When binding input fails. Bypass this by calling {@link ignoreValidationErrors()}.
245+
* @throws ExceptionInterface When input binding fails. Bypass this by calling {@link ignoreValidationErrors()}.
246246
*
247247
* @see setCode()
248248
* @see execute()

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Response
7272
public const HTTP_PRECONDITION_REQUIRED = 428; // RFC6585
7373
public const HTTP_TOO_MANY_REQUESTS = 429; // RFC6585
7474
public const HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431; // RFC6585
75-
public const HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451;
75+
public const HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451; // RFC7725
7676
public const HTTP_INTERNAL_SERVER_ERROR = 500;
7777
public const HTTP_NOT_IMPLEMENTED = 501;
7878
public const HTTP_BAD_GATEWAY = 502;

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public function save()
249249
unset($_SESSION[$key]);
250250
}
251251
}
252-
if ([$key = $this->metadataBag->getStorageKey()] === array_keys($_SESSION)) {
252+
if ($_SESSION && [$key = $this->metadataBag->getStorageKey()] === array_keys($_SESSION)) {
253253
unset($_SESSION[$key]);
254254
}
255255

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,13 @@ public function testRegenerateInvalidSessionIdForNativeFileSessionHandler()
314314
$this->assertTrue($started);
315315
$this->assertSame('&~[', session_id());
316316
}
317+
318+
public function testSaveHandlesNullSessionGracefully()
319+
{
320+
$storage = $this->getStorage();
321+
$_SESSION = null;
322+
$storage->save();
323+
324+
$this->addToAssertionCount(1);
325+
}
317326
}

src/Symfony/Component/Mime/Email.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Email extends Message
4343
private $html;
4444
private $htmlCharset;
4545
private $attachments = [];
46+
private ?AbstractPart $cachedBody = null; // Used to avoid wrong body hash in DKIM signatures with multiple parts (e.g. HTML + TEXT) due to multiple boundaries.
4647

4748
/**
4849
* @return $this
@@ -282,6 +283,7 @@ public function text($body, string $charset = 'utf-8')
282283
throw new \TypeError(sprintf('The body must be a string, a resource or null (got "%s").', get_debug_type($body)));
283284
}
284285

286+
$this->cachedBody = null;
285287
$this->text = $body;
286288
$this->textCharset = $charset;
287289

@@ -312,6 +314,7 @@ public function html($body, string $charset = 'utf-8')
312314
throw new \TypeError(sprintf('The body must be a string, a resource or null (got "%s").', get_debug_type($body)));
313315
}
314316

317+
$this->cachedBody = null;
315318
$this->html = $body;
316319
$this->htmlCharset = $charset;
317320

@@ -342,6 +345,7 @@ public function attach($body, string $name = null, string $contentType = null)
342345
throw new \TypeError(sprintf('The body must be a string or a resource (got "%s").', get_debug_type($body)));
343346
}
344347

348+
$this->cachedBody = null;
345349
$this->attachments[] = ['body' => $body, 'name' => $name, 'content-type' => $contentType, 'inline' => false];
346350

347351
return $this;
@@ -352,6 +356,7 @@ public function attach($body, string $name = null, string $contentType = null)
352356
*/
353357
public function attachFromPath(string $path, string $name = null, string $contentType = null)
354358
{
359+
$this->cachedBody = null;
355360
$this->attachments[] = ['path' => $path, 'name' => $name, 'content-type' => $contentType, 'inline' => false];
356361

357362
return $this;
@@ -368,6 +373,7 @@ public function embed($body, string $name = null, string $contentType = null)
368373
throw new \TypeError(sprintf('The body must be a string or a resource (got "%s").', get_debug_type($body)));
369374
}
370375

376+
$this->cachedBody = null;
371377
$this->attachments[] = ['body' => $body, 'name' => $name, 'content-type' => $contentType, 'inline' => true];
372378

373379
return $this;
@@ -378,6 +384,7 @@ public function embed($body, string $name = null, string $contentType = null)
378384
*/
379385
public function embedFromPath(string $path, string $name = null, string $contentType = null)
380386
{
387+
$this->cachedBody = null;
381388
$this->attachments[] = ['path' => $path, 'name' => $name, 'content-type' => $contentType, 'inline' => true];
382389

383390
return $this;
@@ -388,6 +395,7 @@ public function embedFromPath(string $path, string $name = null, string $content
388395
*/
389396
public function attachPart(DataPart $part)
390397
{
398+
$this->cachedBody = null;
391399
$this->attachments[] = ['part' => $part];
392400

393401
return $this;
@@ -446,6 +454,10 @@ public function ensureValidity()
446454
*/
447455
private function generateBody(): AbstractPart
448456
{
457+
if (null !== $this->cachedBody) {
458+
return $this->cachedBody;
459+
}
460+
449461
$this->ensureValidity();
450462

451463
[$htmlPart, $attachmentParts, $inlineParts] = $this->prepareParts();
@@ -471,6 +483,8 @@ private function generateBody(): AbstractPart
471483
}
472484
}
473485

486+
$this->cachedBody = $part;
487+
474488
return $part;
475489
}
476490

src/Symfony/Component/Mime/Tests/EmailTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,4 +532,24 @@ public function testTextBodyAcceptedTypes()
532532
$email->text($contents);
533533
$this->assertSame($contents, $email->getTextBody());
534534
}
535+
536+
public function testBodyCache()
537+
{
538+
$email = new Email();
539+
$email->from('fabien@symfony.com');
540+
$email->to('fabien@symfony.com');
541+
$email->text('foo');
542+
$body1 = $email->getBody();
543+
$body2 = $email->getBody();
544+
$this->assertSame($body1, $body2, 'The two bodies must reference the same object, so the body cache ensures that the hash for the DKIM signature is unique.');
545+
546+
$email = new Email();
547+
$email->from('fabien@symfony.com');
548+
$email->to('fabien@symfony.com');
549+
$email->text('foo');
550+
$body1 = $email->getBody();
551+
$email->html('<b>bar</b>'); // We change a part to reset the body cache.
552+
$body2 = $email->getBody();
553+
$this->assertNotSame($body1, $body2, 'The two bodies must not reference the same object, so the body cache does not ensure that the hash for the DKIM signature is unique.');
554+
}
535555
}

0 commit comments

Comments
 (0)
0