Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Http/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ public function match(Request $request, bool $fresh = true): ?Route
}

$url = \parse_url($request->getURI(), PHP_URL_PATH);
$url = \is_string($url) ? ($url === '' ? '/' : $url) : '/';
$method = $request->getMethod();
$method = (self::REQUEST_METHOD_HEAD == $method) ? self::REQUEST_METHOD_GET : $method;

Expand Down Expand Up @@ -945,6 +946,7 @@ private function runInternal(Request $request, Response $response): static
$route = self::$wildcardRoute;
$this->route = $route;
$path = \parse_url($request->getURI(), PHP_URL_PATH);
$path = \is_string($path) ? ($path === '' ? '/' : $path) : '/';
$route->path($path);

$this->setRequestResource('route', fn () => $route, []);
Expand Down
36 changes: 36 additions & 0 deletions tests/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,17 @@ public function testCanMatchFreshRoute(): void
}
}

public function testCanMatchRootRouteWhenUriHasNoPath(): void
{
$route = Http::get('/');

$_SERVER['REQUEST_METHOD'] = Http::REQUEST_METHOD_GET;
$_SERVER['REQUEST_URI'] = 'https://example.com?x=1';

$this->assertSame($route, $this->http->match(new Request()));
$this->assertSame($route, $this->http->getRoute());
}

public function testCanRunRequest(): void
{
// Test head requests
Expand Down Expand Up @@ -556,6 +567,31 @@ public function testWildcardRoute(): void
$_SERVER['REQUEST_URI'] = $uri;
}

public function testWildcardRouteWhenUriHasNoPath(): void
{
$method = $_SERVER['REQUEST_METHOD'] ?? null;
$uri = $_SERVER['REQUEST_URI'] ?? null;

$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = 'https://example.com?x=1';

Http::wildcard()
->inject('response')
->action(function ($response) {
$response->send('HELLO');
});

\ob_start();
@$this->http->run(new Request(), new Response());
$result = \ob_get_contents();
\ob_end_clean();

$_SERVER['REQUEST_METHOD'] = $method;
$_SERVER['REQUEST_URI'] = $uri;

$this->assertEquals('HELLO', $result);
}

public function testCallableStringParametersNotExecuted(): void
{
// Test that callable strings (like function names) are not executed
Expand Down
Loading