Skip to content

Commit c3efcb0

Browse files
committed
fixes #18854 - route parameter binding
1 parent 51cad04 commit c3efcb0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Illuminate/Routing/RouteParameterBinder.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public function parameters($request)
5757
*/
5858
protected function bindPathParameters($request)
5959
{
60-
preg_match($this->route->compiled->getRegex(), '/'.$request->decodedPath(), $matches);
60+
$path = '/'.ltrim($request->decodedPath(), '/');
61+
preg_match($this->route->compiled->getRegex(), $path, $matches);
6162

6263
return $this->matchToKeys(array_slice($matches, 1));
6364
}

tests/Routing/RoutingRouteTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,27 @@ public function testControllerCallActionMethodParameters()
452452
$this->assertInstanceOf('Illuminate\Tests\Routing\RoutingTestTeamModel', $values[3]);
453453
}
454454

455+
public function testLeadingParamDoesntReceiveForwardSlashOnEmptyPath()
456+
{
457+
$router = $this->getRouter();
458+
$outer_one = 'abc1234'; // a string that is not one we're testing
459+
$router->get('{one?}', [
460+
'uses' => function ($one = null) use (&$outer_one) {
461+
$outer_one = $one;
462+
return $one;
463+
},
464+
'where' => ['one' => '(.+)'],
465+
]);
466+
467+
$this->assertEquals('', $router->dispatch(Request::create(''))->getContent());
468+
$this->assertNull($outer_one);
469+
// Expects: '' ($one === null)
470+
// Actual: '/' ($one === '/')
471+
472+
$this->assertEquals('foo', $router->dispatch(Request::create('/foo', 'GET'))->getContent());
473+
$this->assertEquals('foo/bar/baz', $router->dispatch(Request::create('/foo/bar/baz', 'GET'))->getContent());
474+
}
475+
455476
/**
456477
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
457478
*/

0 commit comments

Comments
 (0)