Skip to content

Conversation

@ziadoz
Copy link
Contributor

@ziadoz ziadoz commented Nov 19, 2025

This adds a new encoding validation rule that checks the contents of a file matches a specific encoding using mb_check_encoding(). In my case I want to ensure user uploaded files such as spreadsheets from office suite software is actually UTF-8, so it can be safely processed.

It can be used as a typical validation: ['file', 'encoding:utf-8'] or via the file rule builder: File::rule()->encoding('utf-8'). It also works for strings.

@shaedrich
Copy link
Contributor

Would it make sense to have a strict (or loose) flag to allow subsets/supersets, e.g. ascii would allow for utf-8 files as they are ASCII-compliant

@ziadoz
Copy link
Contributor Author

ziadoz commented Nov 19, 2025

@shaedrich I was trying to keep things as simple as possible here.

@taylorotwell
Copy link
Member

Is this rule actually specific to files or is it just for any string?

@ziadoz
Copy link
Contributor Author

ziadoz commented Nov 19, 2025

@taylorotwell It works for both files and strings.

@taylorotwell taylorotwell merged commit 660c653 into laravel:12.x Nov 19, 2025
20 of 66 checks passed
@taylorotwell
Copy link
Member

Thanks

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.

3 participants