diff --git a/DependencyInjection/SwiftmailerTransportFactory.php b/DependencyInjection/SwiftmailerTransportFactory.php index cbc78cc5..8bdd5dff 100644 --- a/DependencyInjection/SwiftmailerTransportFactory.php +++ b/DependencyInjection/SwiftmailerTransportFactory.php @@ -99,7 +99,9 @@ public static function resolveOptions(array $options) ]; if (isset($options['url'])) { - $parts = parse_url($options['url']); + if (false === ($parts = parse_url($options['url']))) { + throw new \InvalidArgumentException(sprintf('Supplied url [%s] is not a valid format.', $options['url'])); + } if (isset($parts['scheme'])) { $options['transport'] = $parts['scheme']; } diff --git a/Tests/DependencyInjection/SwiftmailerTransportFactoryTest.php b/Tests/DependencyInjection/SwiftmailerTransportFactoryTest.php index 050c4b40..61eba1f4 100644 --- a/Tests/DependencyInjection/SwiftmailerTransportFactoryTest.php +++ b/Tests/DependencyInjection/SwiftmailerTransportFactoryTest.php @@ -161,6 +161,33 @@ public function testCreateTransportWithSmtpAndWithoutRequestContext() $this->assertSame($authHandler->getAuthMode(), $options['auth_mode']); } + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Supplied url [smtp://localhost:25&auth_mode=cra-md5] is not a valid format. + */ + public function testCreateTransportWithBadURLFormat() + { + $options = [ + 'url' => 'smtp://localhost:25&auth_mode=cra-md5', + 'transport' => 'smtp', + 'username' => null, + 'password' => null, + 'host' => 'localhost', + 'port' => null, + 'timeout' => 30, + 'source_ip' => null, + 'local_domain' => null, + 'encryption' => null, + 'auth_mode' => null, + ]; + + SwiftmailerTransportFactory::createTransport( + $options, + null, + new \Swift_Events_SimpleEventDispatcher() + ); + } + /** * @dataProvider optionsAndResultExpected */