-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Validator] allow the asterisk to be passed as a string #61826
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
| throw new InvalidOptionsException('The "protocols" option must be "*" when it is a string to allow any protocol.', ['protocols']); | ||
| } | ||
|
|
||
| $protocols = ['*']; |
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.
symfony/src/Symfony/Component/Validator/Constraints/UrlValidator.php
Lines 76 to 81 in 6e48170
| if (['*'] === $constraint->protocols) { | |
| // Use RFC 3986 compliant scheme pattern: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) | |
| $protocols = '[a-zA-Z][a-zA-Z0-9+.-]*'; | |
| } else { | |
| $protocols = implode('|', $constraint->protocols); | |
| } |
Should we handle this case here instead?
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.
I don't think the constraint itself should generate a regex pattern to store it in its public property:
- it is a BC break compared to the existing behavior (changing the type)
- it makes it harder to reuse the metadata for other purposes (generating documentation for instance)
The constraint validator is the one that would generate a regex pattern as it needs it.
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.
btw, your code allows regex injection as it does not escape protocols.
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.
I would accept any strings and cast them to an array: if is_string => (array)
in the validator, we're missing a call to preg_quote on array items!
|
Thank you @xabbuh. |
…` option (xabbuh) This PR was merged into the 7.4 branch. Discussion ---------- [Validator] rework the usage of `'*'` for the `protocols` option following #21398, related to symfony/symfony#61826 Commits ------- 83a9025 rework the usage of '*' for the protocols option
making #60561 easier to use