Open glaubinix opened 1 month ago
Symfony 7.1 introduces a new Charset constraint: https://symfony.com/doc/current/reference/constraints/Charset.html
If you need to stay at 6.4, you can write a custom validator that uses mb_detect_encoding($value, $encodings, $strict)
internally.
Symfony version(s) affected
6.4.9
Description
Validating with invalid UTF8 strings with the
UniqueEntityValidator
leads to SQL errors when using PostgreSQL (likely other SQL flavors too), as the validator passes the value straight to the ORM.How to reproduce
Have an entity with constraints like for instance the below entity
Setting the name to any invalid UTF8 string like in the example below and then validating it can/will result in an SQL error.
When using PostgreSQL, but likely other SQL flavors too, this causes the error below
When the
UniqueEntityValidator
callsfindBy
to check if there are any entities stored in the database.Possible Solution
Would be really helpful to automatically have the
UniqueEntityValidator
reject any strings not matching the expected charset or have aCharset
constraint that could be used to run right before theUniqueEntity
Additional Context
No response