Skip to content

Commit 62c894f

Browse files
committed
Presenter: invalid action throws BadRequestException only during startup
1 parent 41bcb7b commit 62c894f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/Application/UI/Presenter.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,8 @@ public function changeAction($action)
391391
if (is_string($action) && Nette\Utils\Strings::match($action, '#^[a-zA-Z0-9][a-zA-Z0-9_\x7f-\xff]*\z#')) {
392392
$this->action = $action;
393393
$this->view = $action;
394-
395394
} else {
396-
$this->error('Action name is not alphanumeric string.');
395+
throw new Nette\InvalidArgumentException('Action name is not alphanumeric string.');
397396
}
398397
}
399398

@@ -1232,7 +1231,11 @@ private function initGlobalParameters()
12321231
}
12331232

12341233
// init & validate $this->action & $this->view
1235-
$this->changeAction($selfParams[self::ACTION_KEY] ?? self::DEFAULT_ACTION);
1234+
try {
1235+
$this->changeAction($selfParams[self::ACTION_KEY] ?? self::DEFAULT_ACTION);
1236+
} catch (\Throwable $e) {
1237+
$this->error('Action name is not valid.', 0, $e);
1238+
}
12361239

12371240
// init $this->signalReceiver and key 'signal' in appropriate params array
12381241
$this->signalReceiver = $this->getUniqueId();

tests/UI/Presenter.paramChecking.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $presenter->injectPrimary(
3838
Assert::exception(function () use ($presenter) {
3939
$request = new Application\Request('Test', Http\Request::GET, ['action' => []]);
4040
$presenter->run($request);
41-
}, Nette\Application\BadRequestException::class, 'Action name is not alphanumeric string.');
41+
}, Nette\Application\BadRequestException::class, 'Action name is not valid.');
4242

4343

4444
Assert::exception(function () use ($presenter) {

0 commit comments

Comments
 (0)