Skip to content

Commit

Permalink
Url: is not ignoring user & password (BC break) [Closes #63]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 13, 2019
1 parent ea567f7 commit b6033d3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/Http/Url.php
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/Http/Url.canonicalize.phpt
Expand Up @@ -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@'
Expand Down
12 changes: 6 additions & 6 deletions tests/Http/Url.httpScheme.phpt
Expand Up @@ -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);
Expand All @@ -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('');
Expand Down
2 changes: 1 addition & 1 deletion tests/Http/Url.isEqual().phpt
Expand Up @@ -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');
Expand Down

0 comments on commit b6033d3

Please sign in to comment.