Skip to content

Commit 188be3d

Browse files
committed
feature: introduce userInfo encoding tests
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
1 parent 5c7ea47 commit 188be3d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/UriIntegrationTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,26 @@ public function testStringRepresentationWithMultipleSlashes(array $test)
281281
{
282282
$this->assertSame($test['expected'], (string) $test['uri']);
283283
}
284+
285+
/**
286+
* Tests that special chars in `userInfo` must always be URL-encoded to pass RFC3986 compliant URIs where characters
287+
* in username and password MUST NOT contain reserved characters.
288+
* @link https://www.rfc-editor.org/rfc/rfc3986#appendix-A
289+
* This test is taken from https://github.com/guzzle/psr7/blob/3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf/tests/UriTest.php#L679-L688
290+
*/
291+
public function testSpecialCharsInUserInfo(): void
292+
{
293+
$uri = $this->createUri('/')->withUserInfo('foo@bar.com', 'pass#word');
294+
self::assertSame('foo%40bar.com:pass%23word', $uri->getUserInfo());
295+
}
296+
297+
/**
298+
* Tests that userinfo which is already encoded is not encoded twice.
299+
* This test is taken from https://github.com/guzzle/psr7/blob/3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf/tests/UriTest.php#L679-L688
300+
*/
301+
public function testAlreadyEncodedUserInfo(): void
302+
{
303+
$uri = $this->createUri('/')->withUserInfo('foo%40bar.com', 'pass%23word');
304+
self::assertSame('foo%40bar.com:pass%23word', $uri->getUserInfo());
305+
}
284306
}

0 commit comments

Comments
 (0)