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

[Validator] Improvement: provide file basename for constr. violation messages in FileValidator.#26261

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

Conversation

@TheCelavi
Copy link
Contributor

QA
Branch?3.4
Bug fix?no
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsno
LicenseMIT
Doc PRN/A

\Symfony\Component\Validator\Constraints\FileValidator provides absolute path to file on server when user, per example, uploads empty file, too large file, of wrong mime type, etc...

Absolute path to file on server does not have value to the end user, on top of that, exposing it can be a security issue - end user should not be aware of server filesystem.

Basename of file, however, has value (per example: MyAwesomeSheet.xlsx, MyCV.doc, etc..) - if something is wrong with file upload (size, mime, etc...).

If basename is exposed, we can construct messages like: "Your file 'MyCV.doc' is not allowed for upload due to....whatever"...

This PR provides basename of file so end user of\Symfony\Component\Validator\Constraints\FileValidator can construct error messages of higher value for end user.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

Thanks for this proposal
That's a new feature so it should target master.
Can you please add some tests also?

}

$sizeInBytes =filesize($path);
$basename = ($valueinstanceof UploadedFile) ?$value->getClientOriginalName() :basename($path);

Choose a reason for hiding this comment

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

brackets should be remove

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Removed as requested - I use brackets for readability purposes, no side effects

@TheCelavi
Copy link
ContributorAuthor

That's a new feature so it should target master.

Do you want me to create PR on master branch?

Can you please add some tests also?

I have updated tests to reflect this change, so, it is kinda covered already. Only thin that can be tested is getting the basename of file - do you want me to write that test?

@TheCelaviTheCelavi changed the base branch from3.4 tomasterMarch 16, 2018 12:59
@nicolas-grekasnicolas-grekas modified the milestones:4.1,nextApr 20, 2018
@fabpotfabpotforce-pushed thefeature/expose-filename-in-file-validator branch from5892e0e toa77abadCompareOctober 10, 2018 12:29
@fabpot
Copy link
Member

Thank you@TheCelavi.

@fabpotfabpot merged commita77abad intosymfony:masterOct 10, 2018
fabpot added a commit that referenced this pull requestOct 10, 2018
…str. violation messages in FileValidator. (TheCelavi)This PR was squashed before being merged into the 4.2-dev branch (closes#26261).Discussion----------[Validator] Improvement: provide file basename for constr. violation messages in FileValidator.| Q             | A| ------------- | ---| Branch?       | 3.4 <!-- see below -->| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | no| License       | MIT| Doc PR        | N/A`\Symfony\Component\Validator\Constraints\FileValidator` provides absolute path to file on server when user, per example, uploads empty file, too large file, of wrong mime type, etc...Absolute path to file on server does not have value to the end user, on top of that, exposing it can be a security issue - end user should not be aware of server filesystem.Basename of file, however, has value (per example: MyAwesomeSheet.xlsx, MyCV.doc, etc..) - if something is wrong with file upload (size, mime, etc...).If basename is exposed, we can construct messages like: "Your file 'MyCV.doc' is not allowed for upload due to....whatever"...This PR provides basename of file so end user of `\Symfony\Component\Validator\Constraints\FileValidator` can construct error messages of higher value for end user.Commits-------a77abad [Validator] Improvement: provide file basename for constr. violation messages in FileValidator.
@nicolas-grekasnicolas-grekas modified the milestones:next,4.2Nov 1, 2018
This was referencedNov 3, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas requested changes

@fabpotfabpotfabpot approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

4 participants

@TheCelavi@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp