Skip to content

Commit c30bcb1

Browse files
committed
feature: introduce userInfo encoding tests
Signed-off-by: Maximilian Bösing <[email protected]>
1 parent 3867c50 commit c30bcb1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/UriIntegrationTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,28 @@ 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+
*
289+
* This test is taken from {@see https://github.com/guzzle/psr7/blob/3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf/tests/UriTest.php#L679-L688 guzzlehttp/psr7}.
290+
*
291+
* @see https://www.rfc-editor.org/rfc/rfc3986#appendix-A
292+
*/
293+
public function testSpecialCharsInUserInfo(): void
294+
{
295+
$uri = $this->createUri('/')->withUserInfo('[email protected]', 'pass#word');
296+
self::assertSame('foo%40bar.com:pass%23word', $uri->getUserInfo());
297+
}
298+
299+
/**
300+
* Tests that userinfo which is already encoded is not encoded twice.
301+
* This test is taken from {@see https://github.com/guzzle/psr7/blob/3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf/tests/UriTest.php#L679-L688 guzzlehttp/psr7}.
302+
*/
303+
public function testAlreadyEncodedUserInfo(): void
304+
{
305+
$uri = $this->createUri('/')->withUserInfo('foo%40bar.com', 'pass%23word');
306+
self::assertSame('foo%40bar.com:pass%23word', $uri->getUserInfo());
307+
}
284308
}

0 commit comments

Comments
 (0)