Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL-encodes the userInfo component of an URI #253

Merged
merged 4 commits into from Dec 28, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Uri.php
Expand Up @@ -437,9 +437,9 @@ public function withScheme($scheme)

public function withUserInfo($user, $password = null)
{
$info = $user;
$info = rawurlencode($user);
cedx marked this conversation as resolved.
Show resolved Hide resolved
if ($password != '') {
cedx marked this conversation as resolved.
Show resolved Hide resolved
$info .= ':' . $password;
$info .= ':' . rawurlencode($password);
}

if ($this->userInfo === $info) {
Expand Down
7 changes: 7 additions & 0 deletions tests/UriTest.php
Expand Up @@ -680,6 +680,13 @@ public function testExtendingClassesInstantiates()
new ExtendedUriTest('http://h:9/')
);
}

public function testSpecialCharsOfUserInfo()
{
// The `userInfo` must always be URL-encoded.
$uri = (new Uri)->withUserInfo('foo@bar.com', 'pass#word');
$this->assertSame('foo%40bar.com:pass%23word', $uri->getUserInfo());
}
}

class ExtendedUriTest extends Uri
Expand Down