-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Closed
Description
Symfony version(s) affected: 4.3.0, 4.3.1
Description
The auto-validation introduced in #27735 leads to an Assert\Length()
validator to doctrine mapped fields with a length, but breaks for fields with length and type binary
because of an invalid charset.
How to reproduce
- Create an entity with a field mapping including e.g.:
@ORM\Column(type = "binary", length = 4)
. In the following, I call this field$hash
. - Set the value of this field to a raw one, e.g. in the constructor
$this->hash = \hash('crc32', 'whateverYouWantToHash\n...\nTest', true);
- Create a form for this entity (no need for a field for the property
$hash
), you can have the form entirely for another field. Submit & validate the form. It will never be valid, as the Length validator will yield the invalid charset error for our$hash
field.
Possible Solution
A workaround is to either:
- simply disable the autovalidation (for this field)
- overwrite the validation with an
Assert\Length(groups={"notexisting"})
I feel like these are workarounds because I expect the validator to not only read and interpret part, but all of the doctrine annotation.
A possible solution would be to either:
- interpret the whole doctrine annotation
- make
Assert\Length()
charset independent (I do not know if and how this would be possible) - validate only the submitted fields instead of the whole entity
Additional context