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

Skip to content

Commit 18fd4ff

Browse files
committed
Decouple constants from intl
1 parent ac1355d commit 18fd4ff

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ class NoSuspiciousCharacters extends Constraint
2525
{
2626
/**
2727
* Check that a string satisfies the requirements for the specified restriction level
28-
* (by default {@see \Spoofchecker::HIGHLY_RESTRICTIVE}).
28+
* (by default {@see self::RESTRICTION_LEVEL_HIGH}).
2929
*/
3030
public const CHECK_RESTRICTION_LEVEL = 16;
3131

3232
/**
3333
* Check a string for the presence of invisible characters such as zero-width spaces,
3434
* or character sequences that are likely not to display such as multiple occurrences of the same non-spacing mark.
3535
*/
36-
public const CHECK_INVISIBLE = \Spoofchecker::INVISIBLE;
36+
public const CHECK_INVISIBLE = 32;
3737

3838
/** Check a string contains only characters allowed by the configured profile. */
39-
public const CHECK_CHAR_LIMIT = \Spoofchecker::CHAR_LIMIT;
39+
public const CHECK_CHAR_LIMIT = 64;
4040

4141
/**
4242
* Check that a string does not mix numbers from different numbering systems;
@@ -50,14 +50,22 @@ class NoSuspiciousCharacters extends Constraint
5050
*/
5151
public const CHECK_HIDDEN_OVERLAY = 256;
5252

53+
public const RESTRICTION_LEVEL_ASCII = 268435456;
54+
public const RESTRICTION_LEVEL_SINGLE_SCRIPT = 536870912;
55+
public const RESTRICTION_LEVEL_HIGH = 805306368;
56+
public const RESTRICTION_LEVEL_MODERATE = 1073741824;
57+
public const RESTRICTION_LEVEL_MINIMAL = 1342177280;
58+
public const RESTRICTION_LEVEL_NONE = 1610612736;
59+
5360
public $message = 'This value is suspicious.';
5461
public int $checks = self::CHECK_RESTRICTION_LEVEL | self::CHECK_INVISIBLE | self::CHECK_CHAR_LIMIT | self::CHECK_MIXED_NUMBERS | self::CHECK_HIDDEN_OVERLAY;
55-
public int $restrictionLevel = \Spoofchecker::HIGHLY_RESTRICTIVE;
62+
public int $restrictionLevel = self::RESTRICTION_LEVEL_HIGH;
5663
public array $profileLocales = [];
5764
public bool $addCurrentLocaleToProfile = true;
5865

5966
/**
6067
* @param int-mask-of<self::CHECK_*>|null $checks
68+
* @param self::RESTRICTION_LEVEL_*|null $restrictionLevel
6169
*/
6270
public function __construct(
6371
array $options = null,

src/Symfony/Component/Validator/Tests/Constraints/NoSuspiciousCharactersValidatorTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,23 @@ public function testSuspiciousStrings(string $string, array $options)
5252
public static function provideSuspiciousStrings(): iterable
5353
{
5454
yield 'Fails restriction level check because of character outside ASCII range' => ['à',
55-
['restrictionLevel' => \Spoofchecker::ASCII],
55+
['restrictionLevel' => NoSuspiciousCharacters::RESTRICTION_LEVEL_ASCII],
5656
];
5757
yield 'Fails restriction level check because of mixed-script string' => ['àㄚ', [
58-
'restrictionLevel' => \Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE,
58+
'restrictionLevel' => NoSuspiciousCharacters::RESTRICTION_LEVEL_SINGLE_SCRIPT,
5959
'profileLocales' => ['zh_Hant_TW'],
6060
]];
6161
yield 'Fails restriction level check because of disallowed Armenian script' => ['àԱ', [
62-
'restrictionLevel' => \Spoofchecker::HIGHLY_RESTRICTIVE,
62+
'restrictionLevel' => NoSuspiciousCharacters::RESTRICTION_LEVEL_HIGH,
6363
'profileLocales' => ['hy_AM'],
6464
]];
6565
yield 'Fails restriction level check because of disallowed Greek script' => ['àπ', [
66-
'restrictionLevel' => \Spoofchecker::MODERATELY_RESTRICTIVE,
66+
'restrictionLevel' => NoSuspiciousCharacters::RESTRICTION_LEVEL_MODERATE,
6767
'profileLocales' => ['el_GR'],
6868
]];
6969
yield 'Fails restriction level check because of Greek script absent from profile' => ['àπ', [
7070
'checks' => NoSuspiciousCharacters::CHECK_RESTRICTION_LEVEL,
71-
'restrictionLevel' => \Spoofchecker::MINIMALLY_RESTRICTIVE,
71+
'restrictionLevel' => NoSuspiciousCharacters::RESTRICTION_LEVEL_MINIMAL,
7272
]];
7373

7474
yield 'Fails INVISIBLE check because of duplicated non-spacing mark' => ['à̀', [
@@ -84,4 +84,17 @@ public static function provideSuspiciousStrings(): iterable
8484
'checks' => NoSuspiciousCharacters::CHECK_HIDDEN_OVERLAY,
8585
]];
8686
}
87+
88+
public function testConstants(): void
89+
{
90+
$this->assertSame(\Spoofchecker::INVISIBLE, NoSuspiciousCharacters::CHECK_INVISIBLE);
91+
$this->assertSame(\Spoofchecker::CHAR_LIMIT, NoSuspiciousCharacters::CHECK_CHAR_LIMIT);
92+
93+
$this->assertSame(\Spoofchecker::ASCII, NoSuspiciousCharacters::RESTRICTION_LEVEL_ASCII);
94+
$this->assertSame(\Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE, NoSuspiciousCharacters::RESTRICTION_LEVEL_SINGLE_SCRIPT);
95+
$this->assertSame(\Spoofchecker::HIGHLY_RESTRICTIVE, NoSuspiciousCharacters::RESTRICTION_LEVEL_HIGH);
96+
$this->assertSame(\Spoofchecker::MODERATELY_RESTRICTIVE, NoSuspiciousCharacters::RESTRICTION_LEVEL_MODERATE);
97+
$this->assertSame(\Spoofchecker::MINIMALLY_RESTRICTIVE, NoSuspiciousCharacters::RESTRICTION_LEVEL_MINIMAL);
98+
$this->assertSame(\Spoofchecker::UNRESTRICTIVE, NoSuspiciousCharacters::RESTRICTION_LEVEL_NONE);
99+
}
87100
}

0 commit comments

Comments
 (0)