-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Add a NoSuspiciousCharacters
constraint to validate a string is not suspicious
#49300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
NotSuspicious
constraint to validate a string is not a spoof attemptNotSuspicious
constraint to validate a string is not suspicious
f3a7774
to
49baf92
Compare
what about a form option / serializer context entry to block such input by default |
@ro0NL I’m not sure this is necessary: few inputs would be concerned by such validation 🤔 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @MatTheCat Thanks for your work on this this! That looks cool, just left some minor thinking 😁
src/Symfony/Component/Validator/Constraints/NotSuspiciousValidator.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Constraints/NotSuspiciousValidator.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Constraints/NotSuspiciousValidator.php
Outdated
Show resolved
Hide resolved
How does it handle emojis? Could you please add a test case with a simple emoji like “:smiley:”? |
@alexislefebvre emojis belong to the “Common” script and should never be considered suspicious (well unless you set the ASCII restriction level). Not sure this requires a dedicated test case? |
src/Symfony/Component/Validator/Constraints/NotSuspiciousValidator.php
Outdated
Show resolved
Hide resolved
I didn't know that it was built in PHP: https://www.php.net/manual/en/spoofchecker.issuspicious.php The documentation is vague. Sorry for the bad writing, I thought about testing a string that contain an emoji, not necessarily as a dedicated test case. |
0d11716
to
bad8dda
Compare
NotSuspicious
constraint to validate a string is not suspiciousNoSuspiciousCharacters
constraint to validate a string is not suspicious
bad8dda
to
18fd4ff
Compare
src/Symfony/Component/Validator/Tests/Constraints/NoSuspiciousCharactersValidatorTest.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we also need to provide a different message for each restriction level?
No need to, another PR can do it later if needed.
LGTM otherwise, thanks.
src/Symfony/Component/Validator/Constraints/NoSuspiciousCharacters.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Constraints/NoSuspiciousCharactersValidator.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Constraints/NoSuspiciousCharacters.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Constraints/NoSuspiciousCharacters.php
Outdated
Show resolved
Hide resolved
84ed1f0
to
6b86297
Compare
src/Symfony/Component/Validator/Constraints/NoSuspiciousCharactersValidator.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Constraints/NoSuspiciousCharacters.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Constraints/NoSuspiciousCharactersValidator.php
Show resolved
Hide resolved
9c0be08
to
25bb90d
Compare
src/Symfony/Component/Validator/Constraints/NoSuspiciousCharacters.php
Outdated
Show resolved
Hide resolved
f717ff3
to
6e2b092
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks!
please squash while fixing the last µ-comment
src/Symfony/Component/Validator/Tests/Constraints/NoSuspiciousCharactersValidatorTest.php
Outdated
Show resolved
Hide resolved
…tring is not a spoof attempt
6e2b092
to
12f901f
Compare
Thank you @MatTheCat. |
…nstraint (MatTheCat) This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [Validator] Document the new `NoSuspiciousCharacters` constraint Feature PR: symfony/symfony#49300 Commits ------- e4d1b82 [Validator] Document the new `NoSuspiciousCharacters` constraint
Leverage
Spoofchecker::isSuspicious
in a new constraint.