Skip to content

Commit baac1bb

Browse files
committed
UrlImmutable: added withoutUserInfo()
1 parent 3e0259b commit baac1bb

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Http/UrlImmutable.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ public function getPassword(): string
141141
}
142142

143143

144+
/**
145+
* @return static
146+
*/
147+
public function withoutUserInfo()
148+
{
149+
$dolly = clone $this;
150+
$dolly->user = $dolly->password = '';
151+
$dolly->build();
152+
return $dolly;
153+
}
154+
155+
144156
/**
145157
* @return static
146158
*/

tests/Http/UrlImmutable.manipulation.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ test(function () {
2929

3030
$url = $url->withFragment('hello');
3131
Assert::same('//name:secret@localhost:123/p%61th/script.php?arg=value#hello', $url->absoluteUrl);
32+
33+
$url = $url->withoutUserInfo();
34+
Assert::same('//localhost:123/p%61th/script.php?arg=value#hello', $url->absoluteUrl);
3235
});
3336

3437

0 commit comments

Comments
 (0)