Permalink
Browse files

Url: is not ignoring user & password (BC break) [Closes #63]

  • Loading branch information...
dg committed Feb 11, 2019
1 parent 5f82979 commit 1d475ebb4af5b5d42f9173addb0f8c99391f04c1
Showing with 11 additions and 12 deletions.
  1. +3 −4 src/Http/Url.php
  2. +1 −1 tests/Http/Url.canonicalize.phpt
  3. +6 −6 tests/Http/Url.httpScheme.phpt
  4. +1 −1 tests/Http/Url.isEqual().phpt
@@ -351,7 +351,7 @@ public function getAuthority(): string
{
return $this->host === ''
? ''
: ($this->user !== '' && $this->scheme !== 'http' && $this->scheme !== 'https'
: ($this->user !== ''
? rawurlencode($this->user) . ($this->password === '' ? '' : ':' . rawurlencode($this->password)) . '@'
: '')
. $this->host
@@ -410,12 +410,11 @@ public function isEqual($url): bool
ksort($query);
$query2 = $this->query;
ksort($query2);
$http = in_array($this->scheme, ['http', 'https'], true);
return $url->scheme === $this->scheme
&& !strcasecmp($url->host, $this->host)
&& $url->getPort() === $this->getPort()
&& ($http || $url->user === $this->user)
&& ($http || $url->password === $this->password)
&& $url->user === $this->user
&& $url->password === $this->password
&& self::unescape($url->path, '%/') === self::unescape($this->path, '%/')
&& $query === $query2
&& $url->fragment === $this->fragment;
@@ -20,7 +20,7 @@ Assert::same('http://hostname/path?arg=value&arg2=v%20a%26l%3Du%2Be', (string) $
$url = new Url('http://username%3A:password%3A@hostN%61me:60/p%61th%2f%25()?arg=value&arg2=v%20a%26l%3Du%2Be#%61nchor');
$url->canonicalize();
Assert::same('http://hostname:60/path%2F%25()?arg=value&arg2=v%20a%26l%3Du%2Be#anchor', (string) $url);
Assert::same('http://username%3A:password%3A@hostname:60/path%2F%25()?arg=value&arg2=v%20a%26l%3Du%2Be#anchor', (string) $url);
$url = new Url('http://host/%1f%20 %21!%22"%23%24$%25%26&%27\'%28(%29)%2a*%2b+%2c,%2d-%2e.%2f/%300%311%322%333%344%355%366%377%388%399%3a:%3b;%3c<%3d=%3e>%3f%40@'
@@ -15,8 +15,8 @@ require __DIR__ . '/../bootstrap.php';
$url = new Url('http://username%3A:password%3A@hostn%61me:60/p%61th/script.php?%61rg=value#%61nchor');
Assert::same('http://hostname:60/p%61th/script.php?arg=value#anchor', (string) $url);
Assert::same('"http:\/\/hostname:60\/p%61th\/script.php?arg=value#anchor"', json_encode($url));
Assert::same('http://username%3A:password%3A@hostname:60/p%61th/script.php?arg=value#anchor', (string) $url);
Assert::same('"http:\/\/username%3A:password%3A@hostname:60\/p%61th\/script.php?arg=value#anchor"', json_encode($url));
Assert::same('http', $url->scheme);
Assert::same('username:', $url->user);
Assert::same('password:', $url->password);
@@ -26,10 +26,10 @@ Assert::same('/p%61th/script.php', $url->path);
Assert::same('/p%61th/', $url->basePath);
Assert::same('arg=value', $url->query);
Assert::same('anchor', $url->fragment);
Assert::same('hostname:60', $url->authority);
Assert::same('http://hostname:60', $url->hostUrl);
Assert::same('http://hostname:60/p%61th/script.php?arg=value#anchor', $url->absoluteUrl);
Assert::same('http://hostname:60/p%61th/', $url->baseUrl);
Assert::same('username%3A:password%3A@hostname:60', $url->authority);
Assert::same('http://username%3A:password%3A@hostname:60', $url->hostUrl);
Assert::same('http://username%3A:password%3A@hostname:60/p%61th/script.php?arg=value#anchor', $url->absoluteUrl);
Assert::same('http://username%3A:password%3A@hostname:60/p%61th/', $url->baseUrl);
Assert::same('script.php?arg=value#anchor', $url->relativeUrl);
$url->setPath('');
@@ -42,7 +42,7 @@ Assert::false($url->isEqual('http://example.com/?a=456&b=123'));
$url = new Url('http://user:pass@example.com');
Assert::true($url->isEqual('http://example.com'));
Assert::false($url->isEqual('http://example.com'));
$url = new Url('ftp://user:pass@example.com');

0 comments on commit 1d475eb

Please sign in to comment.