diff --git a/src/Dsn.php b/src/Dsn.php index 9e4a708..4388557 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -239,6 +239,14 @@ protected function parseUrlArray($url) $url = array_merge($this->uriKeys, $url); + foreach (['host', 'user', 'pass'] as $key) { + if (!isset($url[$key])) { + continue; + } + + $url[$key] = urldecode($url[$key]); + } + foreach ($url as $key => $val) { $setter = 'set' . ucfirst($key); $this->$setter($val); @@ -289,6 +297,14 @@ protected function toUrlArray($data) { $url = array_intersect_key($data, $this->uriKeys); + foreach (['host', 'user', 'pass'] as $key) { + if (!isset($url[$key])) { + continue; + } + + $url[$key] = urlencode($url[$key]); + } + if ($url['adapter']) { $return = $url['scheme'] . '+' . $url['adapter'] . '://'; } else { @@ -315,7 +331,6 @@ protected function toUrlArray($data) if ($query) { foreach ($query as $key => &$value) { if (is_array($value)) { - $intermediate = []; foreach ($value as $k => $v) { $v = urlencode($v); diff --git a/tests/TestCase/Wrapper/CakePHP/V2/EmailDsnTest.php b/tests/TestCase/Wrapper/CakePHP/V2/EmailDsnTest.php index 40940e7..d81170b 100644 --- a/tests/TestCase/Wrapper/CakePHP/V2/EmailDsnTest.php +++ b/tests/TestCase/Wrapper/CakePHP/V2/EmailDsnTest.php @@ -73,6 +73,21 @@ public function defaultsProvider() 'layout' => false, 'timeout' => 30, ] + ], + [ + 'smtp://user:secret@ssl%3A%2F%2Flocalhost:465/?from=you@localhost&messageId=1&template=0&layout=0&timeout=30', + [ + 'transport' => 'Smtp', + 'host' => 'ssl://localhost', + 'port' => 465, + 'username' => 'user', + 'password' => 'secret', + 'from' => 'you@localhost', + 'messageId' => true, + 'template' => false, + 'layout' => false, + 'timeout' => 30, + ] ] ]; } diff --git a/tests/TestCase/Wrapper/CakePHP/V3/EmailDsnTest.php b/tests/TestCase/Wrapper/CakePHP/V3/EmailDsnTest.php index 1395320..deee1ee 100644 --- a/tests/TestCase/Wrapper/CakePHP/V3/EmailDsnTest.php +++ b/tests/TestCase/Wrapper/CakePHP/V3/EmailDsnTest.php @@ -79,6 +79,21 @@ public function defaultsProvider() 'layout' => false, 'timeout' => 30, ] + ], + [ + 'smtp://user:secret@ssl%3A%2F%2Flocalhost:465/?from=you@localhost&messageId=1&template=0&layout=0&timeout=30', + [ + 'className' => 'Smtp', + 'host' => 'ssl://localhost', + 'port' => 465, + 'username' => 'user', + 'password' => 'secret', + 'from' => 'you@localhost', + 'messageId' => true, + 'template' => false, + 'layout' => false, + 'timeout' => 30, + ] ] ]; }