Skip to content

Commit

Permalink
fix: ensure HTTP verb is lower case
Browse files Browse the repository at this point in the history
HTTP verb in Router must be lower case.
  • Loading branch information
kenjis committed Jun 6, 2023
1 parent d94ebf3 commit 8f8851c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion system/Router/AutoRouterImproved.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function __construct(// @phpstan-ignore-line
*/
public function getRoute(string $uri, string $httpVerb): array
{
$defaultMethod = $httpVerb . ucfirst($this->defaultMethod);
$defaultMethod = strtolower($httpVerb) . ucfirst($this->defaultMethod);
$this->method = $defaultMethod;

$segments = explode('/', $uri);
Expand Down
6 changes: 4 additions & 2 deletions system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class RouteCollection implements RouteCollectionInterface
/**
* The current method that the script is being called by.
*
* @var string
* @var string HTTP verb (lower case) or `*`
*/
protected $HTTPVerb = '*';

Expand Down Expand Up @@ -550,11 +550,13 @@ public function getHTTPVerb(): string
* Sets the current HTTP verb.
* Used primarily for testing.
*
* @param string $verb HTTP verb
*
* @return $this
*/
public function setHTTPVerb(string $verb)
{
$this->HTTPVerb = $verb;
$this->HTTPVerb = strtolower($verb);

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function __construct(RouteCollectionInterface $routes, ?Request $request
$this->controller = $this->collection->getDefaultController();
$this->method = $this->collection->getDefaultMethod();

$this->collection->setHTTPVerb(strtolower($request->getMethod() ?? $_SERVER['REQUEST_METHOD']));
$this->collection->setHTTPVerb($request->getMethod() ?? $_SERVER['REQUEST_METHOD']);

$this->translateURIDashes = $this->collection->shouldTranslateURIDashes();

Expand Down

0 comments on commit 8f8851c

Please sign in to comment.