Skip to content

Commit

Permalink
Better removal of the host from the path
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Jul 30, 2019
1 parent 0848844 commit d782fb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Http/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public static function current(array $props = [], bool $forwarded = false)
}

$uri = Server::get('REQUEST_URI');
$uri = str_replace(Server::get('HTTP_HOST'), '', $uri);
$uri = preg_replace('!^(http|https)\:\/\/' . Server::get('HTTP_HOST') . '!', '', $uri);
$uri = parse_url('http://getkirby.com' . $uri);

$url = new static(array_merge([
Expand Down
16 changes: 13 additions & 3 deletions tests/Http/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testCurrentWithRequestUri()
public function testCurrentWithHostInRequestUri()
{
$_SERVER['HTTP_HOST'] = 'ktest.loc';
$_SERVER['REQUEST_URI'] = '/ktest.loc/';
$_SERVER['REQUEST_URI'] = 'http://ktest.loc/';

$uri = Uri::current();
$this->assertEquals('/', $uri->toString());
Expand All @@ -67,7 +67,7 @@ public function testCurrentWithHostInRequestUri()
public function testCurrentWithHostAndPathInRequestUri()
{
$_SERVER['HTTP_HOST'] = 'ktest.loc';
$_SERVER['REQUEST_URI'] = '/ktest.loc/a/b';
$_SERVER['REQUEST_URI'] = 'http://ktest.loc/a/b';

$uri = Uri::current();
$this->assertEquals('/a/b', $uri->toString());
Expand All @@ -77,13 +77,23 @@ public function testCurrentWithHostAndPathInRequestUri()
public function testCurrentWithHostAndSchemeInRequestUri()
{
$_SERVER['HTTP_HOST'] = 'ktest.loc';
$_SERVER['REQUEST_URI'] = '/http://ktest.loc/';
$_SERVER['REQUEST_URI'] = 'http://ktest.loc/';

$uri = Uri::current();
$this->assertEquals('/', $uri->toString());
$this->assertEquals('', $uri->path());
}

public function testCurrentWithHostInPath()
{
$_SERVER['HTTP_HOST'] = 'ktest.loc';
$_SERVER['REQUEST_URI'] = 'http://ktest.loc/a/b/ktest.loc';

$uri = Uri::current();
$this->assertEquals('/a/b/ktest.loc', $uri->toString());
$this->assertEquals('a/b/ktest.loc', $uri->path());
}

public function testValidScheme()
{
$url = new Uri;
Expand Down

0 comments on commit d782fb7

Please sign in to comment.