File tree 2 files changed +34
-3
lines changed
2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -568,14 +568,33 @@ protected function makeMatchedRoute() : Route
568
568
$ method = 'GET ' ;
569
569
}
570
570
$ url = $ this ->response ->getRequest ()->getUrl ();
571
- $ this ->setMatchedPath ($ url ->getPath ());
571
+ $ path = $ this ->makePath ($ url ->getPath ());
572
+ $ this ->setMatchedPath ($ path );
572
573
$ this ->setMatchedOrigin ($ url ->getOrigin ());
573
574
$ this ->matchedCollection = $ this ->matchCollection ($ url ->getOrigin ());
574
575
if ( ! $ this ->matchedCollection ) {
575
576
return $ this ->matchedRoute = $ this ->getDefaultRouteNotFound ();
576
577
}
577
- return $ this ->matchedRoute = $ this ->matchRoute ($ method , $ this ->matchedCollection , $ url ->getPath ())
578
- ?? $ this ->getAlternativeRoute ($ method , $ this ->matchedCollection );
578
+ return $ this ->matchedRoute = $ this ->matchRoute (
579
+ $ method ,
580
+ $ this ->matchedCollection ,
581
+ $ path
582
+ ) ?? $ this ->getAlternativeRoute ($ method , $ this ->matchedCollection );
583
+ }
584
+
585
+ /**
586
+ * Creates a path without a trailing slash to be able to match both with and
587
+ * without a slash at the end.
588
+ *
589
+ * @since 3.4.3
590
+ *
591
+ * @param string $path
592
+ *
593
+ * @return string
594
+ */
595
+ protected function makePath (string $ path ) : string
596
+ {
597
+ return '/ ' . \trim ($ path , '/ ' );
579
598
}
580
599
581
600
protected function getAlternativeRoute (string $ method , RouteCollection $ collection ) : Route
Original file line number Diff line number Diff line change @@ -179,6 +179,18 @@ public function testMatchRoute() : void
179
179
self ::assertInstanceOf (RouteCollection::class, $ this ->router ->getMatchedCollection ());
180
180
}
181
181
182
+ public function testMatchRouteWithTrailingSlash () : void
183
+ {
184
+ $ this ->prepare ([
185
+ 'REQUEST_METHOD ' => 'PATCH ' ,
186
+ 'REQUEST_URI ' => '/post/25/ ' ,
187
+ ]);
188
+ $ this ->router ->match ();
189
+ self ::assertSame ('post.update ' , $ this ->router ->getMatchedRoute ()->getName ());
190
+ self ::assertSame (['25 ' ], $ this ->router ->getMatchedRoute ()->getActionArguments ());
191
+ self ::assertInstanceOf (RouteCollection::class, $ this ->router ->getMatchedCollection ());
192
+ }
193
+
182
194
public function testGetMatchedUrl () : void
183
195
{
184
196
self ::assertNull ($ this ->router ->getMatchedUrl ());
You can’t perform that action at this time.
0 commit comments