@@ -277,20 +277,20 @@ public static function routePatternsProvider(): array
277277 {
278278 return [
279279 // Route pattern -> http uri
280- // Empty route
281- ['' , '/ ' ],
282280 // Single slash route
283281 ['/ ' , '/ ' ],
284- // Route That Does Not Start With A Slash
285- ['foo ' , '/foo ' ],
286282 // Route That Does Not End In A Slash
287283 ['/foo ' , '/foo ' ],
288284 // Route That Ends In A Slash
289- ['/foo/ ' , '/foo ' ],
285+ ['/foo/ ' , '/foo/ ' ],
290286 // Route That Ends In A double Slash
291- ['/foo// ' , '/foo ' ],
287+ ['/foo// ' , '/foo// ' ],
292288 // Route That contains In A double Slash
293- ['/foo//bar ' , '/foo/bar ' ],
289+ ['/foo//bar ' , '/foo//bar ' ],
290+ // FastRoute optional trailing slash segment matches /foo
291+ ['/foo[/] ' , '/foo ' ],
292+ // FastRoute optional trailing slash segment matches /foo/
293+ ['/foo[/] ' , '/foo/ ' ],
294294 ];
295295 }
296296
@@ -315,6 +315,47 @@ public function testRoutePatterns(string $pattern, string $uri): void
315315 $ this ->assertSame ('Hello World ' , (string )$ response ->getBody ());
316316 }
317317
318+ public static function strictRouteMismatchProvider (): array
319+ {
320+ return [
321+ 'foo does not match foo trailing slash ' => [
322+ '/foo ' , // route pattern
323+ '/foo/ ' , // request URI
324+ ],
325+ 'foo trailing slash does not match foo ' => [
326+ '/foo/ ' , // route pattern
327+ '/foo ' , // request URI
328+ ],
329+ 'foo does not match FOO uppercase ' => [
330+ '/foo ' , // route pattern
331+ '/FOO ' , // request URI
332+ ],
333+ 'route without leading slash does not match ' => [
334+ 'foo ' , // route pattern
335+ '/foo ' , // request URI
336+ ],
337+ ];
338+ }
339+
340+ #[DataProvider('strictRouteMismatchProvider ' )]
341+ public function testStrictRouteMismatch (string $ routePattern , string $ requestUri ): void
342+ {
343+ $ this ->expectException (HttpNotFoundException::class);
344+
345+ $ app = AppFactory::create ();
346+ $ app ->addRoutingMiddleware ();
347+
348+ $ request = $ this
349+ ->getServerRequestFactory ($ app )
350+ ->createServerRequest ('GET ' , $ requestUri );
351+
352+ $ app ->get ($ routePattern , function () {
353+ // noop
354+ });
355+
356+ $ app ->handle ($ request );
357+ }
358+
318359 /********************************************************************************
319360 * Route Groups
320361 *******************************************************************************/
0 commit comments