Skip to content

Commit 62fd642

Browse files
committed
Route: rejects route when constant parameter is not present (BC break?)
Not to generate the first URL for Homepage: default $router->addRoute('/foo', [ 'presenter' => 'Homepage', 'action' => 'default', 'week' => 'upcoming', ]); $router->addRoute('/', 'Homepage:default');
1 parent 17ca816 commit 62fd642

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

src/Routing/Route.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ private function preprocessParams(array &$params): bool
309309
$fixity = $meta[self::Fixity] ?? null;
310310

311311
if (!isset($params[$name])) {
312+
if ($fixity === self::Constant) {
313+
if ($meta[self::Value] === null) {
314+
continue;
315+
}
316+
317+
return false; // wrong parameter value
318+
}
319+
312320
continue; // retains null values
313321
}
314322

tests/Route/fixedParameter.phpt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ testRouteIn($route, '/?const=foo', ['const' => 'hello', 'test' => 'testvalue'],
2121

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

24-
Assert::same(
25-
'http://example.com/',
26-
testRouteOut($route, [])
27-
);
24+
Assert::null(testRouteOut($route, []));
2825

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

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

36-
Assert::same(
37-
'http://example.com/',
38-
testRouteOut($route, ['const' => null])
39-
);
33+
Assert::null(testRouteOut($route, ['const' => null]));

tests/Route/optional.autooptional3.phpt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ use Tester\Assert;
1313
require __DIR__ . '/../bootstrap.php';
1414

1515

16-
$route = new Route('<presenter>/<default=123>/<required>', [
17-
'action' => 'default',
18-
]);
16+
$route = new Route('<presenter>/<default=123>/<required>', []);
1917

2018
testRouteIn($route, '/presenter/');
2119
testRouteIn($route, '/presenter/abc');
@@ -24,7 +22,6 @@ testRouteIn($route, '/presenter/abc/');
2422
testRouteIn($route, '/presenter/abc/xyy', [
2523
'presenter' => 'presenter',
2624
'default' => 'abc',
27-
'action' => 'default',
2825
'test' => 'testvalue',
2926
'required' => 'xyy',
3027
], '/presenter/abc/xyy?test=testvalue');

0 commit comments

Comments
 (0)