Skip to content

Commit e49ca71

Browse files
committed
Route: checking for unexpected < >
1 parent 43fcfc3 commit e49ca71

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/Application/Routers/Route.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ private function setMask($mask, array $metadata)
457457
}
458458
}
459459

460-
if (strpbrk($mask, '?<[]') === FALSE) {
460+
if (strpbrk($mask, '?<>[]') === FALSE) {
461461
$this->re = '#' . preg_quote($mask, '#') . '/?\z#A';
462462
$this->sequence = [$mask];
463463
$this->metadata = $metadata;
@@ -466,7 +466,7 @@ private function setMask($mask, array $metadata)
466466

467467
// PARSE MASK
468468
// <parameter-name[=default] [pattern]> or [ or ] or ?...
469-
$parts = Strings::split($mask, '/<([^>= ]+)(=[^> ]*)? *([^>]*)>|(\[!?|\]|\s*\?.*)/');
469+
$parts = Strings::split($mask, '/<([^<>= ]+)(=[^<> ]*)? *([^<>]*)>|(\[!?|\]|\s*\?.*)/');
470470

471471
$this->xlat = [];
472472
$i = count($parts) - 1;
@@ -509,8 +509,12 @@ private function setMask($mask, array $metadata)
509509
$autoOptional = TRUE;
510510
$aliases = [];
511511
do {
512-
array_unshift($sequence, $parts[$i]);
513-
$re = preg_quote($parts[$i], '#') . $re;
512+
$part = $parts[$i]; // part of path
513+
if (strpbrk($part, '<>') !== FALSE) {
514+
throw new Nette\InvalidArgumentException("Unexpected '$part' in mask '$mask'.");
515+
}
516+
array_unshift($sequence, $part);
517+
$re = preg_quote($part, '#') . $re;
514518
if ($i === 0) {
515519
break;
516520
}

tests/Routers/Route.errors.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ Assert::exception(function () {
1818
Assert::exception(function () {
1919
$route = new Route('a]');
2020
}, Nette\InvalidArgumentException::class, "Missing '[' in mask 'a]'.");
21+
22+
Assert::exception(function () {
23+
$route = new Route('<presenter>/<action');
24+
}, Nette\InvalidArgumentException::class, "Unexpected '/<action' in mask '<presenter>/<action'.");
25+
26+
Assert::exception(function () {
27+
$route = new Route('<presenter>/action>');
28+
}, Nette\InvalidArgumentException::class, "Unexpected '/action>' in mask '<presenter>/action>'.");

0 commit comments

Comments
 (0)