Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 041cb46

Browse files
OskarStarkfabpot
authored andcommitted
[Mailer] Fix parsing Dsn with empty user/password
1 parent e96b0e7 commit 041cb46

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/Symfony/Component/Mailer/Tests/Transport/DsnTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,26 @@ public function fromStringProvider(): iterable
5252
new Dsn('smtp', 'example.com'),
5353
];
5454

55+
yield 'simple dsn including @ sign, but no user/password/token' => [
56+
'scheme://@localhost',
57+
new Dsn('scheme', 'localhost', null, null),
58+
];
59+
60+
yield 'simple dsn including : sign and @ sign, but no user/password/token' => [
61+
'scheme://:@localhost',
62+
new Dsn('scheme', 'localhost', null, null),
63+
];
64+
65+
yield 'simple dsn including user, : sign and @ sign, but no password' => [
66+
'scheme://user1:@localhost',
67+
new Dsn('scheme', 'localhost', 'user1', null),
68+
];
69+
70+
yield 'simple dsn including : sign, password, and @ sign, but no user' => [
71+
'scheme://:pass@localhost',
72+
new Dsn('scheme', 'localhost', null, 'pass'),
73+
];
74+
5575
yield 'simple smtp with custom port' => [
5676
'smtp://user1:[email protected]:99',
5777
new Dsn('smtp', 'example.com', 'user1', 'pass2', 99),

src/Symfony/Component/Mailer/Transport/Dsn.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public static function fromString(string $dsn): self
4949
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN must contain a host (use "default" by default).', $dsn));
5050
}
5151

52-
$user = isset($parsedDsn['user']) ? urldecode($parsedDsn['user']) : null;
53-
$password = isset($parsedDsn['pass']) ? urldecode($parsedDsn['pass']) : null;
52+
$user = '' !== ($parsedDsn['user'] ?? '') ? urldecode($parsedDsn['user']) : null;
53+
$password = '' !== ($parsedDsn['pass'] ?? '') ? urldecode($parsedDsn['pass']) : null;
5454
$port = $parsedDsn['port'] ?? null;
5555
parse_str($parsedDsn['query'] ?? '', $query);
5656

0 commit comments

Comments
 (0)