Skip to content

Commit 562f622

Browse files
committed
Route: action is mandatory when defined as 'Presenter:'
1 parent 4f39fe0 commit 562f622

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Application/Routers/Route.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ class Route extends Nette\Object implements Application\IRouter
112112
public function __construct($mask, $metadata = [], $flags = 0)
113113
{
114114
if (is_string($metadata)) {
115-
$a = strrpos($metadata, ':');
116-
if (!$a) {
115+
$parts = explode(':', $metadata);
116+
if (count($parts) !== 2) {
117117
throw new Nette\InvalidArgumentException("Second argument must be array or string in format Presenter:action, '$metadata' given.");
118118
}
119-
$metadata = [
120-
self::PRESENTER_KEY => substr($metadata, 0, $a),
121-
'action' => $a === strlen($metadata) - 1 ? NULL : substr($metadata, $a + 1),
122-
];
119+
$metadata = [self::PRESENTER_KEY => $parts[0]];
120+
if ($parts[1] !== '') {
121+
$metadata['action'] = $parts[1];
122+
}
123123
} elseif ($metadata instanceof \Closure || $metadata instanceof Nette\Callback) {
124124
if ($metadata instanceof Nette\Callback) {
125125
trigger_error('Nette\Callback is deprecated, use Nette\Utils\Callback::toClosure().', E_USER_DEPRECATED);

tests/Routers/Route.mandatoryAction.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ testRouteIn($route, '/default', 'Default', [
1919
'action' => 'default',
2020
'test' => 'testvalue',
2121
], '/default?test=testvalue');
22+
23+
testRouteIn($route, '/', NULL);

0 commit comments

Comments
 (0)