Skip to content

Commit

Permalink
Route: rejects route when constant parameter is not present (BC break?)
Browse files Browse the repository at this point in the history
Not to generate the first URL for Homepage: default

$router->addRoute('/foo', [
    'presenter' => 'Homepage',
    'action' => 'default',
    'week' => 'upcoming',
]);
$router->addRoute('/', 'Homepage:default');
  • Loading branch information
dg committed Feb 8, 2021
1 parent 30b313f commit b14ecce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ private function preprocessParams(array &$params): bool
$fixity = $meta[self::FIXITY] ?? null;

if (!isset($params[$name])) {
if ($fixity === self::CONSTANT) {
if ($meta[self::VALUE] === null) {
continue;
}
return false; // wrong parameter value
}
continue; // retains null values
}

Expand Down
10 changes: 2 additions & 8 deletions tests/Route/fixedParameter.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ testRouteIn($route, '/?const=foo', ['const' => 'hello', 'test' => 'testvalue'],

testRouteIn($route, '/?const=hello', ['const' => 'hello', 'test' => 'testvalue'], '/?test=testvalue');

Assert::same(
'http://example.com/',
testRouteOut($route, [])
);
Assert::null(testRouteOut($route, []));

Assert::null(testRouteOut($route, ['const' => 'foo']));

Expand All @@ -33,7 +30,4 @@ Assert::same(
testRouteOut($route, ['const' => 'hello'])
);

Assert::same(
'http://example.com/',
testRouteOut($route, ['const' => null])
);
Assert::null(testRouteOut($route, ['const' => null]));
5 changes: 1 addition & 4 deletions tests/Route/optional.autooptional3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


$route = new Route('<presenter>/<default=123>/<required>', [
'action' => 'default',
]);
$route = new Route('<presenter>/<default=123>/<required>', []);

testRouteIn($route, '/presenter/');
testRouteIn($route, '/presenter/abc');
Expand All @@ -24,7 +22,6 @@ testRouteIn($route, '/presenter/abc/');
testRouteIn($route, '/presenter/abc/xyy', [
'presenter' => 'presenter',
'default' => 'abc',
'action' => 'default',
'test' => 'testvalue',
'required' => 'xyy',
], '/presenter/abc/xyy?test=testvalue');
Expand Down

0 comments on commit b14ecce

Please sign in to comment.