Skip to content

Commit f267581

Browse files
committed
Fix UserInfo component
1 parent 725e513 commit f267581

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ All Notable changes to `League\Uri\Interfaces` will be documented in this file
4848

4949
- `UriString::parse` will fail if the URI contains whitespace.
5050
- `UriString::buildUri` allows the `$path` argument to be `null`.
51+
- `UriString::buildAuthority` allows the `$user` argument to be `null` and still generate a user info component.
5152

5253
### Deprecated
5354

UriString.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,18 +266,19 @@ public static function buildAuthority(array $components): ?string
266266
return null;
267267
}
268268

269-
$authority = $components['host'];
270-
if (isset($components['port'])) {
271-
$authority .= ':'.$components['port'];
269+
$userInfo = $components['user'] ?? null;
270+
if (isset($components['pass'])) {
271+
$userInfo .= ':'.$components['pass'];
272272
}
273273

274-
if (!isset($components['user'])) {
275-
return $authority;
274+
$authority = '';
275+
if (isset($userInfo)) {
276+
$authority .= $userInfo.'@';
276277
}
277278

278-
$userInfo = self::buildUserInfo($components);
279-
if (null !== $userInfo) {
280-
return $userInfo.'@'.$authority;
279+
$authority .= $components['host'];
280+
if (isset($components['port'])) {
281+
$authority .= ':'.$components['port'];
281282
}
282283

283284
return $authority;

0 commit comments

Comments
 (0)