8000 [Mailer] Catch missing scheme in DSN by derrabus · Pull Request #31993 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Mailer] Catch missing scheme in DSN #31993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Symfony/Component/Mailer/Tests/TransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,18 @@ public function testFromInvalidDsn()
Transport::fromDsn('some://');
}

public function testNoScheme()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The "//sendmail" mailer DSN must contain a transport scheme.');
Transport::fromDsn('//sendmail');
}

public function testFromInvalidDsnNoHost()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The "?!" mailer DSN must contain a mailer name.');
Transport::fromDsn('?!');
$this->expectExceptionMessage('The "file:///some/path" mailer DSN must contain a mailer name.');
Transport::fromDsn('file:///some/path');
}

public function testFromInvalidTransportName()
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Mailer/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ private static function createTransport(string $dsn, EventDispatcherInterface $d
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN is invalid.', $dsn));
}

if (!isset($parsedDsn['scheme'])) {
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN must contain a transport scheme.', $dsn));
}

if (!isset($parsedDsn['host'])) {
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN must contain a mailer name.', $dsn));
}
Expand Down
0