Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpFoundation] Fix file upload multiple with no files#24198

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:2.7fromenumag:patch-27
Sep 30, 2017

Conversation

@enumag
Copy link
Contributor

@enumagenumag commentedSep 14, 2017
edited
Loading

QA
Branch?2.7
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
Doc PR
<form method="post" enctype="multipart/form-data"><input type="file" multiple name="img[]"><input type="submit"></form><?php$loader =require__DIR__ .'/../app/autoload.php';if ($_SERVER['REQUEST_METHOD'] ==='POST') {$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();var_export($request->files->all()['img']);}

Expected result when I send the form without any files:

array ()

Actual result:

array ( 0 => NULL, )

This causes a problem later when using FileType with multiple option - if no files are sent the form data are[0 => ''] instead of[].

Of course I need to add a test for this.

@xabbuh
Copy link
Member

TheFileType should handle this quite well since#20418.

@enumag
Copy link
ContributorAuthor

enumag commentedSep 14, 2017
edited
Loading

@xabbuh It does not work because the null is somehow converted to an empty string. I don't know when or why. And regardless I believe this should be fixed in HttpFoundation anyway - some people are using HttpFoundation without Forms.

Should I revert the FileType fix as part of this PR? I don't think it's the right place to fix this issue.

@xabbuh
Copy link
Member

Not sure about reverting the change inside theFileType. We may discuss that. However, can you create a test covering the change you are doing here?

@enumag
Copy link
ContributorAuthor

Of course. I wouldn't want you to merge it without a test anyway.

@enumagenumagforce-pushed thepatch-27 branch 2 times, most recently fromd111996 to748223cCompareSeptember 14, 2017 09:36
@enumag
Copy link
ContributorAuthor

enumag commentedSep 14, 2017
edited
Loading

@xabbuh Test added. For the Forms component I'd like to remove theFileType::buildForm() method. Other changes from#20418 should stay.

@yceruto Since you're the author of#20418, can I ask for your opinion?

publicfunctiontestShouldRemoveEmptyUploadedFilesForMultiUpload()
{
$bag =newFileBag(array('file' =>array(
'name' =>array(''),
Copy link
Member

Choose a reason for hiding this comment

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

Is this really the structure that is used when multiple files are submitted?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@xabbuh Yes.

Copy link
ContributorAuthor

@enumagenumagSep 14, 2017
edited
Loading

Choose a reason for hiding this comment

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

To be more precise it's the structure used for<input type="file" name="file[]"> (note the[]), regardless of how many files are actually sent (including 0) and regardless of themultiple attribute.

You can try yourself with the example script I posted above. Just addvar_export($_FILES); somewhere.

Copy link
Member

Choose a reason for hiding this comment

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

For the records, that's also explicitly described here:http://php.net/manual/en/features.file-upload.multiple.php

Copy link
Member

@ycerutoycerutoSep 14, 2017
edited
Loading

Choose a reason for hiding this comment

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

I can't reproduce the issue, thisFileBag with those values returns:

file-bag

according to:

if (UPLOAD_ERR_NO_FILE ==$file['error']) {
$file =null;

the rest is handled onPRE_SUBMIT event insideFileType ifmultiple = true

Copy link
Member

Choose a reason for hiding this comment

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

See test case also:

publicfunctiontestSubmitNullWhenMultiple()
{
$form =$this->factory->create(static::TESTED_TYPE,null,array(
'multiple' =>true,
));
// submitted data when an input file is uploaded without choosing any file
$form->submit(array(null));
$this->assertSame(array(),$form->getData());
$this->assertSame(array(),$form->getNormData());
$this->assertSame(array(),$form->getViewData());
}

Copy link
Member

@xabbuhxabbuh left a comment

Choose a reason for hiding this comment

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

looks good to me

@xabbuhxabbuh added this to the2.7 milestoneSep 14, 2017
@xabbuh
Copy link
Member

@enumag Can you rebase and change the target branch to2.7?

@enumag
Copy link
ContributorAuthor

@xabbuh Sure. Can I ask why? I mean according toSymfony Release Process maintenance for 2.7 already ended. I don't think this qualifies for a security fix.

@xabbuh
Copy link
Member

Symfony is an LTS release it receives bugfix until May 2018.

@enumag
Copy link
ContributorAuthor

Oh right, my mistake. I'll rebase it soon.

xabbuh reacted with thumbs up emoji

@enumagenumag changed the base branch from2.8 to2.7September 14, 2017 12:26
@enumag
Copy link
ContributorAuthor

@xabbuh All done.

@yceruto
Copy link
Member

yceruto commentedSep 14, 2017
edited
Loading

Yep, I thinkbuildForm() and related test case can be removed safely so.

@enumag
Copy link
ContributorAuthor

@xabbuh Should I remove the buildForm here or in another PR? Perhaps it should only be removed in newer symfony versions to prevent regression when new version of Form component is used with old version of HttpFoundation?

@xabbuh
Copy link
Member

Wecould remove the Form related part, but as you said it may hurt people mixing different versions of the HttpFoundation and Form components. Thus, as it doesn't hurt, I'd vote to keep it as is.

@enumag
Copy link
ContributorAuthor

Alright. I will send a PR to Forms later when there is no possibility of such conflict.

@fabpot
Copy link
Member

Thank you@enumag.

@fabpotfabpot merged commitd4f6039 intosymfony:2.7Sep 30, 2017
fabpot added a commit that referenced this pull requestSep 30, 2017
…numag)This PR was merged into the 2.7 branch.Discussion----------[HttpFoundation] Fix file upload multiple with no files| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets || License       | MIT| Doc PR        |```php<form method="post" enctype="multipart/form-data"><input type="file" multiple name="img[]"><input type="submit"></form><?php$loader = require __DIR__ . '/../app/autoload.php';if ($_SERVER['REQUEST_METHOD'] === 'POST') {    $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();    var_export($request->files->all()['img']);}```Expected result when I send the form without any files:```array ()```Actual result:```array ( 0 => NULL, )```This causes a problem later when using FileType with multiple option - if no files are sent the form data are `[0 => '']` instead of `[]`.Of course I need to add a test for this.Commits-------d4f6039 [HttpFoundation] Fix file upload multiple with no files
This was referencedOct 5, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ycerutoycerutoyceruto left review comments

@fabpotfabpotfabpot approved these changes

@xabbuhxabbuhxabbuh approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

2.7

Development

Successfully merging this pull request may close these issues.

5 participants

@enumag@xabbuh@yceruto@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp