Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixes #9 Bridge error when no file is selected #10

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

Closed
wants to merge 2 commits into from

Conversation

ahundiak
Copy link

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #9
License MIT
Doc PR n/a

@nicolas-grekas
Copy link
Member

Please see tests failure (double space + parse error on 5.3)

@dunglas
Copy link
Member

dunglas commented Aug 19, 2015

@stof suggested to fix Symfony directly. What is the selected solution?

@ahundiak
Copy link
Author

I don't see how the S2.7 Request object could be modified without introducing a significant bc break. This is an easy fix which won't impact anything even if the request 3.x object is fixed. And I do want to use the bridge for my 2.3/2.7 projects.

@stof
Copy link
Member

stof commented Aug 20, 2015

@ahundiak avoiding to put null in the array of files would not be a BC break IMO. It would be a bugfix, because the code currently does not respect its expected signature (and we would stop returning null in one of the error case, not add a null value, so it would not be a BC break)

@ahundiak
Copy link
Author

@stof - From the cookbook:

http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html#basic-setup

public function upload()
{
  // the file property can be empty if the field is not required
  if (null === $this->getFile()) {
    return;
  }

I'm guessing that quite a few people are just checking for null and not bothering to check the error status. One could of course argue that the file status should always be checked but I know I don't.

Understand that I'm not arguing against "fixing" the request object. It's definitely the right thing to do in 3.x. But as far as the bridge goes for existing code, I don't see the harm in handling nulls.

@stof
Copy link
Member

stof commented Aug 20, 2015

@ahundiak this is about a file in the Doctrine entity. It has nothing to do with the HttpFoundation error checking (which is checked by the validator component during the form binding in the example you linked.

and if you work with HttpFoundation directly, you have to check the errors otherwise your code is totally broken.

@ahundiak
Copy link
Author

@stof - I'll be glad to submit a pr against the file parameter bag object. The current behavior is documented in a test:

public function testShouldSetEmptyUploadedFilesToNull()
{
    $bag = new FileBag(array('file' => array(
        'name' => '',
        'type' => '',
        'tmp_name' => '',
        'error' => UPLOAD_ERR_NO_FILE,
        'size' => 0,
    )));

    $this->assertNull($bag->get('file'));
}

Easy enough to make the change.

@dunglas
Copy link
Member

dunglas commented Oct 30, 2015

What do you think @symfony/deciders? Should we merge this PR or change the (tested) Behavior in HttpFoundation?

@dunglas
Copy link
Member

dunglas commented Nov 4, 2015

@fabpot what do you think about this one?

@xabbuh
Copy link
Member

xabbuh commented Mar 31, 2016

Imho changing the behaviour in the FileBag class would be a BC break (people might rely on the fact that we return null elements to output error messages) and I don't see where the current code is violating the public interface. So I am 👍 for finishing this PR.

ping @symfony/deciders

@fabpot
Copy link
Member

fabpot commented Apr 1, 2016

👍 for this patch

@@ -86,6 +86,10 @@ private function getFiles(array $uploadedFiles)
$files = array();

foreach ($uploadedFiles as $key => $value) {
if ($value === null) {
Copy link

Choose a reason for hiding this comment

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

YODA: null === $value

Copy link

Choose a reason for hiding this comment

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

I've always been curious why the Symfony source prefers null to come first. What's the reasoning?

Copy link
Member

Choose a reason for hiding this comment

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

@Tobion
Copy link

Tobion commented Apr 1, 2016

👍 for finishing this patch.

@weaverryan
Copy link
Member

Ping @ahundiak - will you be able to make the suggested changes?

@ahundiak
Copy link
Author

When I get time. If someone else want to do then that would be fine with
me. I know the importance of coding standards but it's hard to muster the
energy to follow all of the undocumented ones.

On Sun, Apr 24, 2016 at 1:11 PM, Ryan Weaver [email protected]
wrote:

Ping @ahundiak https://github.com/ahundiak - will you be able to make
the suggested changes?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#10 (comment)

@Danielss89
Copy link

I've fixed the stuff mentioned in code-review, in this PR: Danielss89#1 to @ahundiak original branch. If he doesn't merge within a couple of days, i will create a new PR for this repo instead.

@weaverryan
Copy link
Member

@Danielss89 it looks like your PR got closed? You can totally also make a new PR - if you include the original commits, that would be awesome and we can get this guy taken care of.

@Danielss89
Copy link

Opened a new PR also. See #23

@xabbuh
Copy link
Member

xabbuh commented Jun 6, 2016

closing in favour of #23

@xabbuh xabbuh closed this Jun 6, 2016
Danielss89 added a commit to Danielss89/psr-http-message-bridge that referenced this pull request Sep 14, 2016
Fixes #9 Bridge error when no file is selected symfony#10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants