From 5d6e0a30106b5f647f0b5b88b2c8fbfaa5ea028f Mon Sep 17 00:00:00 2001 From: butschster Date: Wed, 11 May 2016 16:13:43 +0300 Subject: [PATCH] Fix replacing route default parameters. --- src/Illuminate/Routing/Route.php | 4 ++-- tests/Routing/RoutingRouteTest.php | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php index f6535e00ba71..c4ceeea959d4 100755 --- a/src/Illuminate/Routing/Route.php +++ b/src/Illuminate/Routing/Route.php @@ -518,8 +518,8 @@ protected function matchToKeys(array $matches) */ protected function replaceDefaults(array $parameters) { - foreach ($parameters as $key => &$value) { - $value = isset($value) ? $value : Arr::get($this->defaults, $key); + foreach ($parameters as $key => $value) { + $parameters[$key] = isset($value) ? $value : Arr::get($this->defaults, $key); } foreach ($this->defaults as $key => $value) { diff --git a/tests/Routing/RoutingRouteTest.php b/tests/Routing/RoutingRouteTest.php index 81b62d193269..63650245d15c 100644 --- a/tests/Routing/RoutingRouteTest.php +++ b/tests/Routing/RoutingRouteTest.php @@ -277,6 +277,9 @@ public function testRouteParametersDefaultValue() $router->get('foo/{bar?}', ['uses' => 'RouteTestControllerWithParameterStub@returnParameter'])->defaults('bar', 'foo'); $this->assertEquals('foo', $router->dispatch(Request::create('foo', 'GET'))->getContent()); + $router->get('foo/{bar?}', ['uses' => 'RouteTestControllerWithParameterStub@returnParameter'])->defaults('bar', 'foo'); + $this->assertEquals('bar', $router->dispatch(Request::create('foo/bar', 'GET'))->getContent()); + $router->get('foo/{bar?}', function ($bar = '') { return $bar; })->defaults('bar', 'foo'); $this->assertEquals('foo', $router->dispatch(Request::create('foo', 'GET'))->getContent()); }