Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Fix RouteUrlGenerator accepting empty string for required paramenter #30714

Conversation

@MrCrayon
Copy link
Contributor

MrCrayon commented Nov 29, 2019

#30659 fixed RouteUrlGenerator not failing when a required parameter is not passed but it's still not failing if a required parameter is passed empty.

Route::get('/foo/{required}/test/{optional?}')->name('test-route');
route('test-route', ['required' => null, 'optional' => null]);
// UrlGenerationException

route('test-route', ['required' => '', 'optional' => null]);
// /foo//test

I don't think this could be considered an expected behaviour since normally required means set and not empty.

My PR checks if the required parameter is set and it's not an empty string, if this check fails it will look for default Parameter and as last step checks if parameter was optional.

@driesvints driesvints changed the title Fix RouteUrlGenerator accepting empty string for required paramenter [6.x] Fix RouteUrlGenerator accepting empty string for required paramenter Nov 29, 2019
@driesvints

This comment has been minimized.

Copy link
Member

driesvints commented Nov 29, 2019

@MrCrayon tests are failing and you probably want to add a test specifically for this scenario.

@MrCrayon

This comment has been minimized.

Copy link
Contributor Author

MrCrayon commented Nov 29, 2019

@driesvints yes, it's quite strange that route failing on tests it's ok on my end.

Route::get('foo/bar/{baz}')->name('foobar');
route('foobar', ['baz' => 'Taylor']);
// /foo/bar/Taylor

I'll add some tests and try to understand what's happening.

MrCrayon added 2 commits Nov 29, 2019
@MrCrayon

This comment has been minimized.

Copy link
Contributor Author

MrCrayon commented Nov 29, 2019

Test failing was the one with optional parameter passed without key:

Route::get('foo/bar/{baz?}')->name('foobar');
route('foobar', 'taylor');
// or
route('foobar', ['taylor']);

What I needed to do is removing empty parameter from $parameters and let the other methods take care of the rest.

@taylorotwell taylorotwell merged commit dfb4c1c into laravel:6.x Dec 2, 2019
2 checks passed
2 checks passed
continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@driesvints

This comment has been minimized.

Copy link
Member

driesvints commented Dec 5, 2019

@MrCrayon this broke a scenario where 0 is used as a route parameter: #30760

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.