Skip to content

Commit 72fb034

Browse files
committed
bug #39531 [Mailer] Fix parsing Dsn with empty user/password (OskarStark)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Mailer] Fix parsing Dsn with empty user/password | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | no | License | MIT | Doc PR | no While working on a PR for Notifier that user and password would be parsed as an empty string, which is not wrong, but not expected IMO. Thi `scheme://@symfony.com` and `scheme://:@symfony.com` should be a valid scheme with user and pass `null` Another fix would be to check for `://@` and `://:@` and throw an `InvalidArgumentException` WDYT? The final solution will then be applied to the Notifier DSN in `5.1` Commits ------- 041cb46 [Mailer] Fix parsing Dsn with empty user/password
2 parents a316a31 + 041cb46 commit 72fb034

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:pass2@example.com: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)