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

[L6] Route URL Generation fails when giving 0 as a Route Parmater Value #30760

Closed
Sn0wCrack opened this issue Dec 5, 2019 · 6 comments · Fixed by #30768
Closed

[L6] Route URL Generation fails when giving 0 as a Route Parmater Value #30760

Sn0wCrack opened this issue Dec 5, 2019 · 6 comments · Fixed by #30768
Labels

Comments

@Sn0wCrack
Copy link

  • Laravel Version: 6.6.1
  • PHP Version: 7.3.1
  • Database Driver & Version: MySQL, MariaDB 10.4

Description:

It appears when passing through an integer 0 (or any falsey value) to the route() helper or any other route URL generation function, a UrlGenerationException is thrown.

It appears this issue is caused by the following change in this PR: https://github.com/laravel/framework/pull/30714/files#diff-9ffa9921c8542da8cb0059fcbc3ad48aR218-R231

Since this is doing a non-strict type check on the Route Parameter value, it always returns false when any falsey value is given to it (as a blank string is equal to false in non-strict checks)

Steps To Reproduce:

  1. Create a route with a required parameter and no default values, example:
    Route::get('/user/{id}/post/{post_id}', 'PostController@get')->name('user.post');
  2. Attempt to pass through 0 as one of the values, example:
    route('user.post', [ 'id' => 1, 'post_id' => 0 ]);
  3. This should product an exception similar to the following:
    Missing required parameters for [Route: user.post] [URI: user/{id}/post/{post_id}]. (View: ...)
@Sn0wCrack Sn0wCrack changed the title Route URL Generation fails when giving 0 as a Route Parmater Value [L6] Route URL Generation fails when giving 0 as a Route Parmater Value Dec 5, 2019
@driesvints
Copy link
Member

Why would your post id be 0?

@Miguel-Serejo
Copy link

While it is unconventional, ids are typically unsigned integers. 0 is a valid id.

In one particular case, I have users that may or may not have accounts. An external service always attempts to load the user's account balance and doesn't handle null very well, so I use an account with id 0 that always has a balance of 0.

@driesvints
Copy link
Member

Yes that's true. I think this might be an easy fix to just check if it's 0 and let it pass through?

@MrCrayon
Copy link
Contributor

MrCrayon commented Dec 5, 2019

Funny I didn't use !empty just to avoid that and then I missed a =.
Sorry about that, I'll fix it later.

@driesvints
Copy link
Member

Sent in a fix here: #30768

@driesvints
Copy link
Member

We did a new patch release with this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants