Replies: 4 comments
-
Hmm, a lot of the internal code treated |
Beta Was this translation helpful? Give feedback.
-
To clarify, this is a preexisting bug that is made more apparent due to my PR. if you instead passed |
Beta Was this translation helpful? Give feedback.
-
Hmm, it seems according to tests passing an empty string should NOT be allowed. I was trying to see if a change like this would work: diff --git a/src/Illuminate/Routing/RouteUrlGenerator.php b/src/Illuminate/Routing/RouteUrlGenerator.php
index c823243634..5a75e8a935 100644
--- a/src/Illuminate/Routing/RouteUrlGenerator.php
+++ b/src/Illuminate/Routing/RouteUrlGenerator.php
@@ -316,7 +316,8 @@ protected function replaceNamedParameters($path, &$parameters)
} elseif (isset($this->defaultParameters[$m[1]])) {
return $this->defaultParameters[$m[1]];
} elseif (isset($parameters[$m[1]])) {
- Arr::pull($parameters, $m[1]);
+ // If there's neither a provided value nor a default value, we just use the empty string...
+ return Arr::pull($parameters, $m[1]);
}
return $m[0]; That however makes this test fail: public static function providerRouteParameters()
{
return [
[['test' => 123]],
[['one' => null, 'test' => 123]],
[['one' => '', 'test' => 123]],
];
}
#[DataProvider('providerRouteParameters')]
public function testUrlGenerationForControllersRequiresPassingOfRequiredParameters($parameters)
{
$this->expectException(UrlGenerationException::class);
$url = new UrlGenerator(
$routes = new RouteCollection,
Request::create('http://www.foo.com:8080/')
);
$route = new Route(['GET'], 'foo/{one}/{two?}/{three?}', ['as' => 'foo', function () {
//
}]);
$routes->add($route);
$this->assertSame('http://www.foo.com:8080/foo?test=123', $url->route('foo', $parameters));
} But the expectation with which this issue is reported is that passing an empty string (third case in the provider) should work. What my changes do is turn So I think in your case you should just make the parameter optional. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your extensive testing @stancl. This issue caught me by surprise in several projects, since several parts relied on this unintended behavior, and works fine before. Based on your explanation, I understand that it was a bug, so moving forward, I will just fix the issue in my projects. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
12.6.0
PHP Version
8.2.28
Database Driver & Version
No response
Description
Previously, passing an empty string to
route()
's$parameters
worked without problem.Let's say a route is defined like this:
When the route is called like this, it works in the previous version, but fails in the latest version:
Probably related to #54811. Ping @stancl .
Steps To Reproduce
route()
.Beta Was this translation helpful? Give feedback.
All reactions