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

Skip to content

FileValidator filenameMaxLength constraint #58482

Closed
@e-repo

Description

@e-repo

Symfony version(s) affected

7.1.*

Description

When attempting to validate a file using the #[Assert\File] constraint, the filenameMaxLength of the filename is incorrectly calculated if the name contains non-Latin characters.

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

How to reproduce

  1. Create a file with a name containing more then 20 non-Latin characters.
  2. Validate the file using #[Assert\File] with the filenameMaxLength: 20 constraint.
  3. Observe the validation result.

Possible Solution

On line 143, the function strlen needs to be replaced with mb_strlen.

File: FileValidator

This will ensure proper handling of filenames containing multibyte characters, such as non-Latin characters, when calculating the string length.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions