Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

Commit

Permalink
fix(http): empty request uri is an empty path (/)
Browse files Browse the repository at this point in the history
  • Loading branch information
leocavalcante committed Jan 27, 2021
1 parent 042132c commit 5c69776
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Http/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function path(): string
}

$query_string = strpos($request_uri, '?');
$request_uri = $query_string ? substr($request_uri, 0, $query_string) : $request_uri;
$request_uri = $query_string === false ? $request_uri : substr($request_uri, 0, $query_string);
$request_uri = rawurldecode($request_uri);
$script_path = str_replace('\\', '/', \dirname($script_name));

Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/Http/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ public function testFuzzyQueryString()
$this->assertSame('/bar/baz', Http\path());
}

public function testEmptyRequestUri()
{
$_SERVER['REQUEST_URI'] = '';
$this->assertSame('/', Http\path());

$_SERVER['REQUEST_URI'] = '/';
$this->assertSame('/', Http\path());

$_SERVER['REQUEST_URI'] = '?foo=bar';
$this->assertSame('/', Http\path());

$_SERVER['REQUEST_URI'] = '/?foo=bar';
$this->assertSame('/', Http\path());
}

protected function setUp(): void
{
$_GET = $_POST = $_REQUEST = $_COOKIE = $_SESSION = ['foo' => 'bar'];
Expand Down

0 comments on commit 5c69776

Please sign in to comment.