-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Closed
Copy link
Description
Symfony version(s) affected
6.3.4
Description
Error messages doesn't change while use construct parameters to change them
This applies to the following parameters:
restrictionLevelMessage,
invisibleMessage,
mixedNumbersMessage,
hiddenOverlayMessage
And maybe more
How to reproduce
- Create a class with fields that contains NoSuspiciousCharacters constraint.
- Change the message text through parameters (for example through: restrictionLevelMessage)
- Try to validate this class and see what message have come (I use the suspicious example from symfony doc page: "ѕymfony.com")
For example:
UserPersonalDataDto.php
class UserPersonalDataDto {
#[Assert\NoSuspiciousCharacters(restrictionLevelMessage: "dummyError")]
private string $firstName;
// getters/setters etc
}
UserController.php
class UserController extends AbstractController {
#[Route('/dummy-controller')]
public function personalData()
{
$personalData = $serializer->deserialize($request->getContent(), InputUserPersonalDataDto::class, 'json');
$violations = $validator->validate($personalData);
if ($violations->count() > 0) {
$violationsArr = $violations->getIterator()->getArrayCopy();
return $this->json($violationsArr);
}
return $this->json('');
}
}
- Should be "dummyError" and I get "This value contains characters that are not allowed by the current restriction-level."
Possible Solution
To change the code of construct of the NoSuspiciousCharacters class from:
$this->restrictionLevelMessage ??= $restrictionLevelMessage;
$this->invisibleMessage ??= $invisibleMessage;
$this->mixedNumbersMessage ??= $mixedNumbersMessage;
$this->hiddenOverlayMessage ??= $hiddenOverlayMessage;
$this->checks ??= $checks;
$this->restrictionLevel ??= $restrictionLevel;
$this->locales ??= $locales;
to:
$this->restrictionLevelMessage = $restrictionLevelMessage ?? $this->restrictionLevelMessage;
$this->invisibleMessage = $invisibleMessage ?? $this->invisibleMessage;
$this->mixedNumbersMessage = $mixedNumbersMessage ?? $this->mixedNumbersMessage;
$this->hiddenOverlayMessage = $hiddenOverlayMessage ?? $this->hiddenOverlayMessage;
$this->checks = $checks ?? $this->checks;
$this->restrictionLevel = $restrictionLevel ?? $this->restrictionLevel;
$this->locales = $locales ?? $this->locales;
Additional Context
No response