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] AddfilenameCharset andfilenameCountUnit options toFile constraint#58485

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:7.3fromIssamRaouf:fix_58482
Mar 1, 2025

Conversation

IssamRaouf
Copy link
Contributor

@IssamRaoufIssamRaouf commentedOct 7, 2024
edited by OskarStark
Loading

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
IssuesFix#58482
LicenseMIT

@carsonbotcarsonbot added this to the6.4 milestoneOct 7, 2024
@carsonbotcarsonbot changed the title[Validator][FileValidator] filenameLength bug non-Latin characters ,replace strlen with mb_strlen to count characters instead of bytes[Validator] [FileValidator] filenameLength bug non-Latin characters ,replace strlen with mb_strlen to count characters instead of bytesOct 7, 2024
Copy link
Contributor

@OskarStarkOskarStark left a comment

Choose a reason for hiding this comment

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

Please add a testcase to avoid further regression

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedOct 8, 2024
edited
Loading

I'm 👎 here: the length in bytes is what matters. Eg a storage can have a 255-max string field counted in bytes, and this validator guards against longer filenames. Validating in code points makes it really hard to validate any predictable maxlength.

Also, nothing tells this accepts only UTF-8 (it doesn't, bytes are bytes, no encoding expected here).

@IssamRaouf
Copy link
ContributorAuthor

IssamRaouf commentedOct 8, 2024
edited
Loading

Hello@nicolas-grekas

For the context of thefilenameMaxLength constraint option, from its name alone, it clearly suggests a validation onthe string's length.

let's take this example :

file-to-upload.pdf (Latin characters)

  • character count = 14
  • mb_strlen($basename) = 14
  • strlen($basename) = 14

файл-завантаження.pdf (non-Latin characters) each character can require 1 to 4 bytes

  • character count = 17
  • mb_strlen($basename) = 17
  • strlen($basename) = 33;

#[Assert\File(
maxSize: '10M',
mimeTypes: ['application/pdf'],
filenameMaxLength: 20,
)]

Result:
Latin characters: passes
Non-Latin characters: fails validation

I find this contradictory 😅.

wazum reacted with thumbs up emoji

@IssamRaouf
Copy link
ContributorAuthor

Hello@OskarStark

ok, I'm waiting for the issue to be validated

OskarStark reacted with thumbs up emoji

@nicolas-grekas
Copy link
Member

We could make this opt-in, eg with a countUnit and a charset option (names taken from the Length constraint)

IssamRaouf reacted with thumbs up emoji

@IssamRaoufIssamRaouf changed the title[Validator] [FileValidator] filenameLength bug non-Latin characters ,replace strlen with mb_strlen to count characters instead of bytes[Validator] [FileValidator] filenameLength bug non-Latin characters ,add options Charset and Count unitOct 14, 2024
@nicolas-grekasnicolas-grekas modified the milestones:6.4,7.2Nov 2, 2024
@nicolas-grekasnicolas-grekas added Feature and removed Bug labelsNov 2, 2024
@IssamRaoufIssamRaouf changed the title[Validator] [FileValidator] filenameLength bug non-Latin characters ,add options Charset and Count unit[Validator] Add filenameCharset and filenameCountUnit options to File constraintNov 2, 2024
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
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.

LGTM, here are some minor last changes.
Please also rebase to target 7.3 since this is a new feature.
And move the changelog lines in the 7.3 section.

IssamRaouf reacted with thumbs up emoji
@OskarStarkOskarStark changed the title[Validator] Add filenameCharset and filenameCountUnit options to File constraint[Validator] AddfilenameCharset andfilenameCountUnit options toFile constraintFeb 10, 2025
@IssamRaoufIssamRaouf changed the base branch from6.4 to7.3February 16, 2025 12:42
$payload,
$filenameCharset,
$filenameCountUnit,
$filenameCharsetMessage
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$filenameCharsetMessage
$filenameCharsetMessage,

@fabpot
Copy link
Member

Thank you@IssamRaouf.

IssamRaouf reacted with thumbs up emoji

@fabpotfabpot merged commit46e00d5 intosymfony:7.3Mar 1, 2025
7 of 9 checks passed
@fabpotfabpot mentioned this pull requestMay 2, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@OskarStarkOskarStarkOskarStark left review comments

@xabbuhxabbuhxabbuh left review comments

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@lyrixxlyrixxAwaiting requested review from lyrixx

@ycerutoycerutoAwaiting requested review from yceruto

@chalasrchalasrAwaiting requested review from chalasr

@dunglasdunglasAwaiting requested review from dunglas

@jderussejderusseAwaiting requested review from jderusse

Assignees
No one assigned
Projects
None yet
Milestone
7.3
Development

Successfully merging this pull request may close these issues.

FileValidator filenameMaxLength constraint
6 participants
@IssamRaouf@nicolas-grekas@fabpot@OskarStark@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp