Skip to content

Commit

Permalink
Fix zero parameter for routes
Browse files Browse the repository at this point in the history
Routes should be allowed to accept a 0 as a route parameter.
  • Loading branch information
driesvints committed Dec 5, 2019
1 parent 5b1b367 commit 3639c0c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/RouteUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ protected function replaceRouteParameters($path, array &$parameters)
protected function replaceNamedParameters($path, &$parameters)
{
return preg_replace_callback('/\{(.*?)(\?)?\}/', function ($m) use (&$parameters) {
if (isset($parameters[$m[1]]) && $parameters[$m[1]] != '') {
if (isset($parameters[$m[1]]) && ($parameters[$m[1]] != '' || $parameters[$m[1]] === 0)) {
return Arr::pull($parameters, $m[1]);
} elseif (isset($this->defaultParameters[$m[1]])) {
return $this->defaultParameters[$m[1]];
Expand Down
2 changes: 2 additions & 0 deletions tests/Routing/RoutingUrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public function testBasicRouteGeneration()
$this->assertSame('/foo/bar?foo=bar', $url->route('foo', ['foo' => 'bar'], false));
$this->assertSame('http://www.foo.com/foo/bar/taylor/breeze/otwell?fly=wall', $url->route('bar', ['taylor', 'otwell', 'fly' => 'wall']));
$this->assertSame('http://www.foo.com/foo/bar/otwell/breeze/taylor?fly=wall', $url->route('bar', ['boom' => 'taylor', 'baz' => 'otwell', 'fly' => 'wall']));
$this->assertSame('http://www.foo.com/foo/bar/0', $url->route('foobar', 0));
$this->assertSame('http://www.foo.com/foo/bar/2', $url->route('foobar', 2));
$this->assertSame('http://www.foo.com/foo/bar/taylor', $url->route('foobar', 'taylor'));
$this->assertSame('/foo/bar/taylor/breeze/otwell?fly=wall', $url->route('bar', ['taylor', 'otwell', 'fly' => 'wall'], false));
Expand All @@ -261,6 +262,7 @@ public function testBasicRouteGeneration()
$this->assertSame('http://www.foo.com/foo/bar', $url->route('optional'));
$this->assertSame('http://www.foo.com/foo/bar', $url->route('optional', ['baz' => null]));
$this->assertSame('http://www.foo.com/foo/bar', $url->route('optional', ['baz' => '']));
$this->assertSame('http://www.foo.com/foo/bar/0', $url->route('optional', ['baz' => 0]));
$this->assertSame('http://www.foo.com/foo/bar/taylor', $url->route('optional', 'taylor'));
$this->assertSame('http://www.foo.com/foo/bar/taylor', $url->route('optional', ['taylor']));
$this->assertSame('http://www.foo.com/foo/bar/taylor?breeze', $url->route('optional', ['taylor', 'breeze']));
Expand Down

0 comments on commit 3639c0c

Please sign in to comment.