8000 Merge branch '4.4' into 5.2 · symfony/symfony@950e144 · GitHub
[go: up one dir, main page]

Skip to content

Commit 950e144

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: bug #40427 [Console] Stop accepting ints as InputOption defaults Fix fingerprint when context is not serializable
2 parents dc8a43b + bbf786c commit 950e144

File tree

4 files changed

+49
-11
lines changed

4 files changed

+49
-11
lines changed

src/Symfony/Bridge/Twig/Mime/BodyRenderer.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function render(Message $message): void
4949

5050
$previousRenderingKey = $messageContext[__CLASS__] ?? null;
5151
unset($messageContext[__CLASS__]);
52-
$currentRenderingKey = md5(serialize([$messageContext, $message->getTextTemplate(), $message->getHtmlTemplate()]));
52+
$currentRenderingKey = $this->getFingerPrint($message);
5353
if ($previousRenderingKey === $currentRenderingKey) {
5454
return;
5555
}
@@ -77,6 +77,23 @@ public function render(Message $message): void
7777
$message->context($message->getContext() + [__CLASS__ => $currentRenderingKey]);
7878
}
7979

80+
private function getFingerPrint(TemplatedEmail $message): string
81+
{
82+
$messageContext = $message->getContext();
83+
unset($messageContext[__CLASS__]);
84+
85+
$payload = [$messageContext, $message->getTextTemplate(), $message->getHtmlTemplate()];
86+
try {
87+
$serialized = serialize($payload);
88+
} catch (\Exception $e) {
89+
// Serialization of 'Closure' is not allowed
90+
// Happens when context contain a closure, in that case, we assume that context always change.
91+
$serialized = random_bytes(8);
92+
}
93+
94+
return md5($serialized);
95+
}
96+
8097
private function convertHtmlToText(string $html): string
8198
{
8299
if (null !== $this->converter) {

src/Symfony/Bridge/Twig/Tests/Mime/BodyRendererTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,27 @@ public function testRenderedOnce()
100100
$this->assertEquals('reset', $email->getTextBody());
101101
}
102102

103+
public function testRenderedOnceUnserializableContext()
104+
{
105+
$twig = new Environment(new ArrayLoader([
106+
'text' => 'Text',
107+
]));
108+
$renderer = new BodyRenderer($twig);
109+
$email = (new TemplatedEmail())
110+
->to('fabien@symfony.com' 8000 ;)
111+
->from('helene@symfony.com')
112+
;
113+
$email->textTemplate('text');
114+
$email->context([
115+
'foo' => static function () {
116+
return 'bar';
117+
},
118+
]);
119+
120+
$renderer->render($email);
121+
$this->assertEquals('Text', $email->getTextBody());
122+
}
123+
103124
private function prepareEmail(?string $text, ?string $html, array $context = []): TemplatedEmail
104125
{
105126
$twig = new Environment(new ArrayLoader([

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,9 @@ public function addArgument(string $name, int $mode = null, string $description
395395
/**
396396
* Adds an option.
397397
*
398-
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
399-
* @param int|null $mode The option mode: One of the InputOption::VALUE_* constants
400-
* @param string|string[]|int|bool|null $default The default value (must be null for InputOption::VALUE_NONE)
398+
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
399+
* @param int|null $mode The option mode: One of the InputOption::VALUE_* constants
400+
* @param string|string[]|bool|null $default The default value (must be null for InputOption::VALUE_NONE)
401401
*
402402
* @throws InvalidArgumentException If option mode is invalid or incompatible
403403
*

src/Symfony/Component/Console/Input/InputOption.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ class InputOption
3333
private $description;
3434

3535
/**
36-
* @param string $name The option name
37 6D40 -
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
38-
* @param int|null $mode The option mode: One of the VALUE_* constants
39-
* @param string $description A description text
40-
* @param string|string[]|int|bool|null $default The default value (must be null for self::VALUE_NONE)
36+
* @param string $name The option name
37+
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
38+
* @param int|null $mode The option mode: One of the VALUE_* constants
39+
* @param string $description A description text
40+
* @param string|string[]|bool|null $default The default value (must be null for self::VALUE_NONE)
4141
*
4242
* @throws InvalidArgumentException If option mode is invalid or incompatible
4343
*/
@@ -149,7 +149,7 @@ public function isArray()
149149
/**
150150
* Sets the default value.
151151
*
152-
* @param string|string[]|int|bool|null $default The default value
152+
* @param string|string[]|bool|null $default The default value
153153
*
154154
* @throws LogicException When incorrect default value is given
155155
*/
@@ -173,7 +173,7 @@ public function setDefault($default = null)
173173
/**
174174
* Returns the default value.
175175
*
176-
* @return string|string[]|int|bool|null The default value
176+
* @return string|string[]|bool|null The default value
177177
*/
178178
public function getDefault()
179179
{

0 commit comments

Comments
 (0)
0