Permalink
Browse files

Routers: parameter 'presenter' is validated outside of routers

  • Loading branch information...
dg committed Feb 10, 2019
1 parent 6cc1e56 commit 5caafccaad4d966228d32f004856177f4a950140
@@ -106,9 +106,13 @@ public function createInitialRequest(): Request
{
$params = $this->router->match($this->httpRequest);
$presenter = $params[UI\Presenter::PRESENTER_KEY] ?? null;
if ($params === null || $presenter === null) {
if ($params === null || !is_string($presenter)) {
throw new BadRequestException('No route for HTTP request.');
} elseif ($presenter === null) {
throw new Nette\InvalidStateException('Missing presenter in route definition.');
}
unset($params[UI\Presenter::PRESENTER_KEY]);
return new Request(
$presenter,
@@ -243,15 +243,10 @@ public function match(Nette\Http\IRequest $httpRequest): ?array
}
}
// 5) BUILD Request
if (!isset($params[self::PRESENTER_KEY])) {
throw new Nette\InvalidStateException('Missing presenter in route definition.');
} elseif (!is_string($params[self::PRESENTER_KEY])) {
return null;
}
if (isset($this->metadata[self::MODULE_KEY], $params[self::MODULE_KEY])) {
$params[self::PRESENTER_KEY] = $params[self::MODULE_KEY] . ':' . $params[self::PRESENTER_KEY];
// 5) PARAMETER MODULE
$presenter = $params[self::PRESENTER_KEY] ?? null;
if (isset($this->metadata[self::MODULE_KEY], $params[self::MODULE_KEY]) && is_string($presenter)) {
$params[self::PRESENTER_KEY] = $params[self::MODULE_KEY] . ':' . $presenter;
}
unset($params[self::MODULE_KEY]);
@@ -41,7 +41,7 @@ public function match(Nette\Http\IRequest $httpRequest): ?array
$params = $route->match($httpRequest);
if ($params !== null) {
$presenter = $params[self::PRESENTER_KEY] ?? null;
if (strncmp($presenter, 'Nette:', 6)) {
if (is_string($presenter) && strncmp($presenter, 'Nette:', 6)) {
$params[self::PRESENTER_KEY] = $this->module . $presenter;
}
return $params;
@@ -70,11 +70,10 @@ public function match(Nette\Http\IRequest $httpRequest): ?array
$params += $this->defaults;
$presenter = $params[self::PRESENTER_KEY] ?? null;
if (!is_string($presenter)) {
return null;
if (is_string($presenter)) {
$params[self::PRESENTER_KEY] = $this->module . $presenter;
}
$params[self::PRESENTER_KEY] = $this->module . $presenter;
return $params;
}
@@ -111,7 +111,9 @@ private function analyse(Nette\Application\IRouter $router, string $module = '')
} catch (\Exception $e) {
}
if ($params !== null) {
$params['presenter'] = $module . ($params['presenter'] ?? '');
if ($module) {
$params['presenter'] = $module . ($params['presenter'] ?? '');
}
$matched = 'may';
if ($this->matched === null) {
$this->matched = $params;
@@ -22,7 +22,7 @@ test(function () {
$httpRequest = new Http\Request($url);
$req = $router->match($httpRequest);
Assert::null($req);
Assert::same(['presenter' => ['foo']], $req);
});
test(function () {
@@ -31,5 +31,5 @@ test(function () {
$httpRequest = new Http\Request($url);
$req = $router->match($httpRequest);
Assert::null($req);
Assert::same([], $req);
});

0 comments on commit 5caafcc

Please sign in to comment.