Skip to content

Conversation

@xabbuh
Copy link
Member

@xabbuh xabbuh commented Sep 24, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? no
Deprecations? no
Issues
License MIT

making #60561 easier to use

@carsonbot carsonbot added this to the 7.4 milestone Sep 24, 2025
@carsonbot carsonbot changed the title [Validator] allow the asterisk to be passed as a string [Validator] allow the asterisk to be passed as a string Sep 24, 2025
throw new InvalidOptionsException('The "protocols" option must be "*" when it is a string to allow any protocol.', ['protocols']);
}

$protocols = ['*'];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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!

@nicolas-grekas
Copy link
Member

Thank you @xabbuh.

@nicolas-grekas nicolas-grekas merged commit b1ef2a4 into symfony:7.4 Sep 24, 2025
10 of 11 checks passed
@xabbuh xabbuh deleted the pr-60561 branch September 24, 2025 10:05
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Sep 24, 2025
…` 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants