Skip to content
Snippets Groups Projects
Commit 8504d429 authored by Larry Garfield's avatar Larry Garfield Committed by Alex Bronstein
Browse files

Allow a trailing / to still match as if it weren't there.

parent fa58bbef
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -55,7 +55,7 @@ public function __construct(Connection $connection, $table = 'router') {
*/
public function matchRequestPartial(Request $request) {
$path = $request->getPathInfo();
$path = rtrim($request->getPathInfo(), '/');
$parts = array_slice(array_filter(explode('/', $path)), 0, MatcherDumper::MAX_PARTS);
......
......@@ -127,6 +127,35 @@ function testOutlinePathMatch() {
$this->assertNotNull($routes->get('route_b'), 'The second matching route was not found.');
}
/**
* Confirms that a trailing slash on the request doesn't result in a 404.
*/
function testOutlinePathMatchTrailingSlash() {
$connection = Database::getConnection();
$matcher = new PathMatcher($connection, 'test_routes');
$this->fixtures->createTables($connection);
$dumper = new MatcherDumper($connection, 'test_routes');
$dumper->addRoutes($this->fixtures->complexRouteCollection());
$dumper->dump();
$path = '/path/1/one/';
$request = Request::create($path, 'GET');
$routes = $matcher->matchRequestPartial($request);
// All of the matching paths have the correct pattern.
foreach ($routes as $route) {
$this->assertEqual($route->compile()->getPatternOutline(), '/path/%/one', 'Found path has correct pattern');
}
$this->assertEqual(count($routes->all()), 2, 'The correct number of routes was found.');
$this->assertNotNull($routes->get('route_a'), 'The first matching route was found.');
$this->assertNotNull($routes->get('route_b'), 'The second matching route was not found.');
}
/**
* Confirms that we can find routes whose pattern would match the request.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment