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

[5.0] File upload is broken when submitting a form without selecting a file. #6423

Closed
wants to merge 4 commits into from
Closed

Conversation

jonathanpmartins
Copy link

"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!

"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!
@jonathanpmartins jonathanpmartins changed the title File upload is broken when submitting a form without selecting a file. [5.0] File upload is broken when submitting a form without selecting a file. Nov 16, 2014
return (new static)->duplicate(

$request->query->all(), $request->request->all(), $request->attributes->all(),
$request->query->all(), $request->request->all(), $request->attributes->all(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs please.

@lucasmichot
Copy link
Contributor

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)
Copy link
Member

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.

Copy link
Author

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.

Copy link
Contributor

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)

Copy link
Member

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. :)

Copy link
Author

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.
@jonathanpmartins
Copy link
Author

Hope it pass all tests and correct this bug.

@ghost
Copy link

ghost commented Nov 17, 2014

You can simplify your code by using the array_filter function.

@jonathanpmartins
Copy link
Author

@pespantelis your are right, I'm making a new commit.

@jonathanpmartins
Copy link
Author

👍

@jonathanpmartins
Copy link
Author

Seems like this bug has been corrected by this pull request: #6256

Thank you all! :)

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 this pull request may close these issues.

3 participants