-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.0] File upload is broken when submitting a form without selecting a file. #6423
Conversation
"I open a pull request here too, because I dont know the right place to put it. if is here in laravel framework, or there in the illuminate repository. illuminate/http#14" File upload is broken when submitting a form without selecting a file in Laravel 5! My tests revealed that with this tweek the problem described at this issue are resolved: #6189 Credits to @Marwelln This resolves a problem that occours in Symfony on the FileBag.php file, convertFileInformation() method. It receaves a empty array file and than returns NULL, if no files was selected on the upload. In this case "FileBag->set('image', NULL)" receives NULL, and that is what is dispatching a throw in Symfony. I misunderstood the problem, and try attempt to do a pull request on symfony, but it was denied: symfony/symfony#12486 I don't make unit tests, but this will no more break my code flow. I'm not sure if this is the real deal! If someone could look deeper into the problem, I appreciated!
return (new static)->duplicate( | ||
|
||
$request->query->all(), $request->request->all(), $request->attributes->all(), | ||
$request->query->all(), $request->request->all(), $request->attributes->all(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tabs please.
…a file. Correct some tips by @GrahamCampbell
tests? |
@@ -599,11 +599,19 @@ public static function createFromBase(SymfonyRequest $request) | |||
{ | |||
if ($request instanceof static) return $request; | |||
|
|||
$files = []; | |||
foreach ($request->files->all() as $index => $file) { | |||
if (null !== $file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use: $file !== null
. No yoda conditions please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm noob yet, but I desire to get better, and I'm very glad to learn from you the NOT yoda condition for this case!
Please @GrahamCampbell, teach me the right way to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonathanpmartins Yound Padawan, do this instead:
if ($file !== null)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yoda conditions are a symfony standard. Laravel doesn't use them. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ow...yeah, now I understand that. Thank you very much!!
Thanks to @GrahamCampbell and @lucasmichot to teach me to not use Yoda conditions.
Hope it pass all tests and correct this bug. |
You can simplify your code by using the array_filter function. |
Credits for the though @pespantelis
@pespantelis your are right, I'm making a new commit. |
👍 |
Seems like this bug has been corrected by this pull request: #6256 Thank you all! :) |
"I open a pull request here too, because I dont know the right place to put it. if is here in laravel framework, or there in the illuminate repository. illuminate/http#14"
File upload is broken when submitting a form without selecting a file in Laravel 5! My tests revealed that with this tweek the problem described at this issue are resolved: #6189
Credits to @Marwelln
This resolves a problem that occours in Symfony on the FileBag.php file, convertFileInformation() method. It receaves a empty array file and than returns NULL, if no files was selected on the upload. In this case "FileBag->set('image', NULL)" receives NULL, and that is what is dispatching a throw in Symfony.
I misunderstood the problem, and try attempt to do a pull request on symfony, but it was denied: symfony/symfony#12486
I don't make unit tests, but this will no more break my code flow. I'm not sure if this is the real deal! If someone could look deeper into the problem, I appreciated!