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] When calling UploadedFile::getErrorMessage() to a file which has no error and is uploaded successfully, it should not return an error#54304

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

Open
ArmCyber wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromArmCyber:7.1

Conversation

ArmCyber
Copy link

@ArmCyberArmCyber commentedMar 15, 2024
edited by stof
Loading

When callingSymfony\Component\HttpFoundation\File\UploadedFile::getErrorMessage() for an uploaded file which has no error and is uploaded successfully, should not give any error message.
Before this changes it returned The file "%s" was not uploaded due to an unknown error..
After this changes, it will return an empty string.

QA
Branch?7.1
Bug fix?yes
New feature?no
Deprecations?no
Issuesno
LicenseMIT

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbotcarsonbot changed the titleWhen calling UploadedFile::getErrorMessage() to a file which has no error and is uploaded successfully, it should not return an error[HttpFoundation] When calling UploadedFile::getErrorMessage() to a file which has no error and is uploaded successfully, it should not return an errorMar 15, 2024
@smnandre
Copy link
Member

I fear this contradict the implementation of themove() method

Ifthis->isValid() returnsfalse, with your change the method would throw an exception with no message.

/**     * Moves the file to a new location.     *     * @throws FileException if, for any reason, the file could not have been moved     */publicfunction move(string$directory, ?string$name =null):File    {if ($this->isValid()) {

@nicolas-grekas
Copy link
Member

Not sure what you mean@smnandre, can you elaborate or share a test case?

@smnandre
Copy link
Member

smnandre commentedMar 18, 2024
edited
Loading

publicfunctiontestInvalidFile(){$this->expectException(FileException::class);$this->expectExceptionMessage('The file "original.gif" was not uploaded due to an unknown error.');$file =newUploadedFile(__DIR__.'/Fixtures/test.gif','original.gif','image/gif',    );$file->move(__DIR__.'/Fixtures/directory');}
Testing Symfony\Component\HttpFoundation\Tests\File\UploadedFileTest...................F..............                                34 / 34 (100%)Time: 00:00.024, Memory: 12.00 MBThere was 1 failure:1) Symfony\Component\HttpFoundation\Tests\File\UploadedFileTest::testInvalidFile- Failed asserting that exception message '' contains 'The file "original.gif" was not uploaded due to an unknown error.'.
ArmCyber reacted with eyes emoji

@smnandre
Copy link
Member

The error message is used as exception message, so it seems to me this code was a failsafe if "something went wrong".

@welcoMattic
Copy link
Member

I guess we should add a new case at the end ofmove method to handle\UPLOAD_ERR_OK error, in order to have an empty string fromUploadedFile::getErrorMessage(), but a legit exception message thrown bymove method on the use case provided by@smnandre. WDYT?

@smnandre
Copy link
Member

I'm wondering if we can handle this very-specific use case in another way, because your changes make sense and are easier to "read" than this special "no error but an error" case.

If no, your solution seems very sensible yes!

@ArmCyber
Copy link
Author

ArmCyber commentedApr 8, 2024
edited
Loading

Thanks@smnandre for the review!

I'm considering renaming the original method "getErrorMessage()" to private "getExceptionMessage()" and creating a new "getErrorMessage()" method, which will check if "$this->error === \UPLOAD_ERR_OK", and if it does, it will return null (or an empty string to ensure backward compatibility); otherwise, it will internally call "getExceptionMessage()". Then, in the "move()" method, we can utilize the "getExceptionMessage()" method.

What do you think?

P.S. I'll also add your test case to the UploadedFileTest.php.

@smnandre
Copy link
Member

Seems perfect to me.

@nicolas-grekas ?

ArmCyber reacted with hooray emoji

…rror and is uploaded successfully, it should not return an error
@ArmCyber
Copy link
Author

Thanks@smnandre!
@nicolas-grekas, what do you think about these changes?

@xabbuhxabbuh modified the milestones:7.1,5.4May 15, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
5.4
Development

Successfully merging this pull request may close these issues.

7 participants
@ArmCyber@carsonbot@smnandre@nicolas-grekas@welcoMattic@GromNaN@xabbuh

[8]ページ先頭

©2009-2025 Movatter.jp