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

Skip to content

Commit 9c0be08

Browse files
committed
Automatically enable CHAR_LIMIT check when allowed locales are configured
1 parent 25bb90d commit 9c0be08

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/Symfony/Component/Validator/Constraints/NoSuspiciousCharacters.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ class NoSuspiciousCharacters extends Constraint
5050
*/
5151
public const CHECK_INVISIBLE = 32;
5252

53-
/** Check a string contains only characters from the configured locales. */
54-
public const CHECK_CHAR_LIMIT = 64;
55-
5653
/**
5754
* Check that a string does not mix numbers from different numbering systems;
5855
* for example “8” (Digit Eight) and “৪” (Bengali Digit Four).
@@ -89,7 +86,7 @@ class NoSuspiciousCharacters extends Constraint
8986
public string $mixedNumbersMessage = 'Mixed numbers check failed.';
9087
public string $hiddenOverlayMessage = 'Hidden overlay check failed.';
9188

92-
public int $checks = self::CHECK_RESTRICTION_LEVEL | self::CHECK_INVISIBLE | self::CHECK_CHAR_LIMIT | self::CHECK_MIXED_NUMBERS | self::CHECK_HIDDEN_OVERLAY;
89+
public int $checks = self::CHECK_RESTRICTION_LEVEL | self::CHECK_INVISIBLE | self::CHECK_MIXED_NUMBERS | self::CHECK_HIDDEN_OVERLAY;
9390
public ?int $restrictionLevel = null;
9491
public ?array $locales = null;
9592

src/Symfony/Component/Validator/Constraints/NoSuspiciousCharactersValidator.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*/
2222
class NoSuspiciousCharactersValidator extends ConstraintValidator
2323
{
24+
private const CHECK_CHAR_LIMIT = 64;
25+
2426
private const CHECK_ERROR = [
2527
NoSuspiciousCharacters::CHECK_RESTRICTION_LEVEL => [
2628
'code' => NoSuspiciousCharacters::RESTRICTION_LEVEL_ERROR,
@@ -30,7 +32,7 @@ class NoSuspiciousCharactersValidator extends ConstraintValidator
3032
'code' => NoSuspiciousCharacters::INVISIBLE_ERROR,
3133
'messageProperty' => 'invisibleMessage',
3234
],
33-
NoSuspiciousCharacters::CHECK_CHAR_LIMIT => [
35+
self::CHECK_CHAR_LIMIT => [
3436
'code' => NoSuspiciousCharacters::CHAR_LIMIT_ERROR,
3537
'messageProperty' => 'charLimitMessage',
3638
],
@@ -74,7 +76,11 @@ public function validate(mixed $value, Constraint $constraint)
7476
if ($constraint->restrictionLevel) {
7577
$checker->setRestrictionLevel($constraint->restrictionLevel);
7678
}
77-
$checker->setAllowedLocales(implode(',', $constraint->locales ?? $this->defaultLocales));
79+
80+
if ($allowedLocales = $constraint->locales ?? $this->defaultLocales) {
81+
$checker->setAllowedLocales($allowedLocales);
82+
$constraint->checks &= self::CHECK_CHAR_LIMIT;
83+
}
7884

7985
$checker->setChecks($constraint->checks);
8086

0 commit comments

Comments
 (0)