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
This commit is contained in:
Nicolas Grekas 2019-10-18 13:24:32 +02:00
commit f771faf925
5 changed files with 34 additions and 23 deletions

View File

@ -263,25 +263,18 @@ final class Dotenv
do { do {
if ("'" === $this->data[$this->cursor]) { if ("'" === $this->data[$this->cursor]) {
$value = ''; $len = 0;
++$this->cursor;
while ("\n" !== $this->data[$this->cursor]) { do {
if ("'" === $this->data[$this->cursor]) { if ($this->cursor + ++$len === $this->end) {
break; $this->cursor += $len;
}
$value .= $this->data[$this->cursor];
++$this->cursor;
if ($this->cursor === $this->end) {
throw $this->createFormatException('Missing quote to end the value'); throw $this->createFormatException('Missing quote to end the value');
} }
} } while ("'" !== $this->data[$this->cursor + $len]);
if ("\n" === $this->data[$this->cursor]) {
throw $this->createFormatException('Missing quote to end the value'); $v .= substr($this->data, 1 + $this->cursor, $len - 1);
} $this->cursor += 1 + $len;
++$this->cursor;
$v .= $value;
} elseif ('"' === $this->data[$this->cursor]) { } elseif ('"' === $this->data[$this->cursor]) {
$value = ''; $value = '';
++$this->cursor; ++$this->cursor;

View File

@ -40,7 +40,7 @@ class DotenvTest extends TestCase
['FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"], ['FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"],
['FOO="foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo...\n ^ line 1 offset 8"], ['FOO="foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo...\n ^ line 1 offset 8"],
['FOO=\'foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo...\n ^ line 1 offset 8"], ['FOO=\'foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo...\n ^ line 1 offset 8"],
['FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 8"], ['FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 9"],
['export FOO', "Unable to unset an environment variable in \".env\" at line 1.\n...export FOO...\n ^ line 1 offset 10"], ['export FOO', "Unable to unset an environment variable in \".env\" at line 1.\n...export FOO...\n ^ line 1 offset 10"],
['FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"], ['FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"],
['FOO= BAR', "Whitespace are not supported before the value in \".env\" at line 1.\n...FOO= BAR...\n ^ line 1 offset 4"], ['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 @@ class DotenvTest extends TestCase
['FOO="bar\rfoo"', ['FOO' => "bar\rfoo"]], ['FOO="bar\rfoo"', ['FOO' => "bar\rfoo"]],
['FOO=\'bar\nfoo\'', ['FOO' => 'bar\nfoo']], ['FOO=\'bar\nfoo\'', ['FOO' => 'bar\nfoo']],
['FOO=\'bar\rfoo\'', ['FOO' => 'bar\rfoo']], ['FOO=\'bar\rfoo\'', ['FOO' => 'bar\rfoo']],
["FOO='bar\nfoo'", ['FOO' => "bar\nfoo"]],
['FOO=" FOO "', ['FOO' => ' FOO ']], ['FOO=" FOO "', ['FOO' => ' FOO ']],
['FOO=" "', ['FOO' => ' ']], ['FOO=" "', ['FOO' => ' ']],
['PATH="c:\\\\"', ['PATH' => 'c:\\']], ['PATH="c:\\\\"', ['PATH' => 'c:\\']],

View File

@ -17,6 +17,7 @@ use Symfony\Component\Mailer\Exception\HttpTransportException;
use Symfony\Component\Mailer\SentMessage; use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport\AbstractApiTransport; use Symfony\Component\Mailer\Transport\AbstractApiTransport;
use Symfony\Component\Mime\Email; use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\NamedAddress;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface; use Symfony\Contracts\HttpClient\ResponseInterface;
@ -75,11 +76,15 @@ class MandrillApiTransport extends AbstractApiTransport
'html' => $email->getHtmlBody(), 'html' => $email->getHtmlBody(),
'text' => $email->getTextBody(), 'text' => $email->getTextBody(),
'subject' => $email->getSubject(), 'subject' => $email->getSubject(),
'from_email' => $envelope->getSender()->toString(), 'from_email' => $envelope->getSender()->getAddress(),
'to' => $this->getRecipients($email, $envelope), 'to' => $this->getRecipients($email, $envelope),
], ],
]; ];
if ($envelope->getSender() instanceof NamedAddress) {
$payload['message']['from_name'] = $envelope->getSender()->getName();
}
foreach ($email->getAttachments() as $attachment) { foreach ($email->getAttachments() as $attachment) {
$headers = $attachment->getPreparedHeaders(); $headers = $attachment->getPreparedHeaders();
$disposition = $headers->getHeaderBody('Content-Disposition'); $disposition = $headers->getHeaderBody('Content-Disposition');
@ -119,10 +124,16 @@ class MandrillApiTransport extends AbstractApiTransport
$type = 'cc'; $type = 'cc';
} }
$recipients[] = [ $recipientPayload = [
'email' => $recipient->toString(), 'email' => $recipient->getAddress(),
'type' => $type, 'type' => $type,
]; ];
if ($recipient instanceof NamedAddress) {
$recipientPayload['name'] = $recipient->getName();
}
$recipients[] = $recipientPayload;
} }
return $recipients; return $recipients;

View File

@ -89,15 +89,15 @@ class Inline
$result = self::parseScalar($value, $flags, null, $i, null === $tag, $references); $result = self::parseScalar($value, $flags, null, $i, null === $tag, $references);
} }
if (null !== $tag && '' !== $tag) {
return new TaggedValue($tag, $result);
}
// some comments are allowed at the end // some comments are allowed at the end
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) { if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename); throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
} }
if (null !== $tag && '' !== $tag) {
return new TaggedValue($tag, $result);
}
return $result; return $result;
} finally { } finally {
if (isset($mbEncoding)) { if (isset($mbEncoding)) {

View File

@ -167,6 +167,12 @@ class InlineTest extends TestCase
Inline::parse('{ foo: bar } bar'); Inline::parse('{ foo: bar } bar');
} }
public function testParseInvalidTaggedSequenceShouldThrowException()
{
$this->expectException('Symfony\Component\Yaml\Exception\ParseException');
Inline::parse('!foo { bar: baz } qux', Yaml::PARSE_CUSTOM_TAGS);
}
public function testParseScalarWithCorrectlyQuotedStringShouldReturnString() public function testParseScalarWithCorrectlyQuotedStringShouldReturnString()
{ {
$value = "'don''t do somthin'' like that'"; $value = "'don''t do somthin'' like that'";