Skip to content

Commit f771faf

Browse files
Merge branch '4.3' into 4.4
* 4.3: [Dotenv] allow LF in single-quoted strings [Yaml] Throw exception for tagged invalid inline elements [Mailer] Fix Mandrill Transport API payload with named addresses
2 parents b9ba0c5 + 0b4c37a commit f771faf

File tree

5 files changed

+34
-23
lines changed

5 files changed

+34
-23
lines changed

src/Symfony/Component/Dotenv/Dotenv.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -263,25 +263,18 @@ private function lexValue(): string
263263

264264
do {
265265
if ("'" === $this->data[$this->cursor]) {
266-
$value = '';
267-
++$this->cursor;
266+
$len = 0;
268267

269-
while ("\n" !== $this->data[$this->cursor]) {
270-
if ("'" === $this->data[$this->cursor]) {
271-
break;
272-
}
273-
$value .= $this->data[$this->cursor];
274-
++$this->cursor;
268+
do {
269+
if ($this->cursor + ++$len === $this->end) {
270+
$this->cursor += $len;
275271

276-
if ($this->cursor === $this->end) {
277272
throw $this->createFormatException('Missing quote to end the value');
278273
}
279-
}
280-
if ("\n" === $this->data[$this->cursor]) {
281-
throw $this->createFormatException('Missing quote to end the value');
282-
}
283-
++$this->cursor;
284-
$v .= $value;
274+
} while ("'" !== $this->data[$this->cursor + $len]);
275+
276+
$v .= substr($this->data, 1 + $this->cursor, $len - 1);
277+
$this->cursor += 1 + $len;
285278
} elseif ('"' === $this->data[$this->cursor]) {
286279
$value = '';
287280
++$this->cursor;

src/Symfony/Component/Dotenv/Tests/DotenvTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function getEnvDataWithFormatErrors()
4040
['FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"],
4141
['FOO="foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo...\n ^ line 1 offset 8"],
4242
['FOO=\'foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo...\n ^ line 1 offset 8"],
43-
['FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 8"],
43+
['FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 9"],
4444
['export FOO', "Unable to unset an environment variable in \".env\" at line 1.\n...export FOO...\n ^ line 1 offset 10"],
4545
['FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"],
4646
['FOO= BAR', "Whitespace are not supported before the value in \".env\" at line 1.\n...FOO= BAR...\n ^ line 1 offset 4"],
@@ -115,6 +115,7 @@ public function getEnvData()
115115
['FOO="bar\rfoo"', ['FOO' => "bar\rfoo"]],
116116
['FOO=\'bar\nfoo\'', ['FOO' => 'bar\nfoo']],
117117
['FOO=\'bar\rfoo\'', ['FOO' => 'bar\rfoo']],
118+
["FOO='bar\nfoo'", ['FOO' => "bar\nfoo"]],
118119
['FOO=" FOO "', ['FOO' => ' FOO ']],
119120
['FOO=" "', ['FOO' => ' ']],
120121
['PATH="c:\\\\"', ['PATH' => 'c:\\']],

src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillApiTransport.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Mailer\SentMessage;
1818
use Symfony\Component\Mailer\Transport\AbstractApiTransport;
1919
use Symfony\Component\Mime\Email;
20+
use Symfony\Component\Mime\NamedAddress;
2021
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
2122
use Symfony\Contracts\HttpClient\HttpClientInterface;
2223
use Symfony\Contracts\HttpClient\ResponseInterface;
@@ -75,11 +76,15 @@ private function getPayload(Email $email, Envelope $envelope): array
7576
'html' => $email->getHtmlBody(),
7677
'text' => $email->getTextBody(),
7778
'subject' => $email->getSubject(),
78-
'from_email' => $envelope->getSender()->toString(),
79+
'from_email' => $envelope->getSender()->getAddress(),
7980
'to' => $this->getRecipients($email, $envelope),
8081
],
8182
];
8283

84+
if ($envelope->getSender() instanceof NamedAddress) {
85+
$payload['message']['from_name'] = $envelope->getSender()->getName();
86+
}
87+
8388
foreach ($email->getAttachments() as $attachment) {
8489
$headers = $attachment->getPreparedHeaders();
8590
$disposition = $headers->getHeaderBody('Content-Disposition');
@@ -119,10 +124,16 @@ protected function getRecipients(Email $email, Envelope $envelope): array
119124
$type = 'cc';
120125
}
121126

122-
$recipients[] = [
123-
'email' => $recipient->toString(),
127+
$recipientPayload = [
128+
'email' => $recipient->getAddress(),
124129
'type' => $type,
125130
];
131+
132+
if ($recipient instanceof NamedAddress) {
133+
$recipientPayload['name'] = $recipient->getName();
134+
}
135+
136+
$recipients[] = $recipientPayload;
126137
}
127138

128139
return $recipients;

src/Symfony/Component/Yaml/Inline.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ public static function parse(string $value = null, int $flags = 0, array $refere
8989
$result = self::parseScalar($value, $flags, null, $i, null === $tag, $references);
9090
}
9191

92-
if (null !== $tag && '' !== $tag) {
93-
return new TaggedValue($tag, $result);
94-
}
95-
9692
// some comments are allowed at the end
9793
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
9894
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
9995
}
10096

97+
if (null !== $tag && '' !== $tag) {
98+
return new TaggedValue($tag, $result);
99+
}
100+
101101
return $result;
102102
} finally {
103103
if (isset($mbEncoding)) {

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ public function testParseInvalidSequenceShouldThrowException()
167167
Inline::parse('{ foo: bar } bar');
168168
}
169169

170+
public function testParseInvalidTaggedSequenceShouldThrowException()
171+
{
172+
$this->expectException('Symfony\Component\Yaml\Exception\ParseException');
173+
Inline::parse('!foo { bar: baz } qux', Yaml::PARSE_CUSTOM_TAGS);
174+
}
175+
170176
public function testParseScalarWithCorrectlyQuotedStringShouldReturnString()
171177
{
172178
$value = "'don''t do somthin'' like that'";

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy