Skip to content
Permalink
Browse files

Remove host from REQUEST_URI in Uri class (Fix #1830)

  • Loading branch information...
bastianallgeier committed Jun 11, 2019
1 parent 90920b9 commit 234cd750e8214252ddef0b55376174fe2c1641b8
Showing with 48 additions and 1 deletion.
  1. +3 −1 src/Http/Uri.php
  2. +45 −0 tests/Http/UriTest.php
@@ -246,7 +246,9 @@ public static function current(array $props = [], bool $forwarded = false)
return static::$current;
}
$uri = parse_url('http://getkirby.com' . Server::get('REQUEST_URI'));
$uri = Server::get('REQUEST_URI');
$uri = str_replace(Server::get('HTTP_HOST'), '', $uri);
$uri = parse_url('http://getkirby.com' . $uri);
$url = new static(array_merge([
'scheme' => Server::https() === true ? 'https' : 'http',
@@ -39,6 +39,51 @@ public function testClone()
$this->assertEquals('http://getkirby.com/yay?foo=bar', $clone->toString());
}
public function testCurrentInCli()
{
$uri = Uri::current();
$this->assertEquals('/', $uri->toString());
}
public function testCurrentWithRequestUri()
{
$_SERVER['REQUEST_URI'] = '/a/b';
$uri = Uri::current();
$this->assertEquals('/a/b', $uri->toString());
$this->assertEquals('a/b', $uri->path());
}
public function testCurrentWithHostInRequestUri()
{
$_SERVER['HTTP_HOST'] = 'ktest.loc';
$_SERVER['REQUEST_URI'] = '/ktest.loc/';
$uri = Uri::current();
$this->assertEquals('/', $uri->toString());
$this->assertEquals('', $uri->path());
}
public function testCurrentWithHostAndPathInRequestUri()
{
$_SERVER['HTTP_HOST'] = 'ktest.loc';
$_SERVER['REQUEST_URI'] = '/ktest.loc/a/b';
$uri = Uri::current();
$this->assertEquals('/a/b', $uri->toString());
$this->assertEquals('a/b', $uri->path());
}
public function testCurrentWithHostAndSchemeInRequestUri()
{
$_SERVER['HTTP_HOST'] = 'ktest.loc';
$_SERVER['REQUEST_URI'] = '/http://ktest.loc/';
$uri = Uri::current();
$this->assertEquals('/', $uri->toString());
$this->assertEquals('', $uri->path());
}
public function testValidScheme()
{
$url = new Uri;

0 comments on commit 234cd75

Please sign in to comment.
You can’t perform that action at this time.