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
[Routing] Add Requirement, a collection of universal regular-expressions constants to use as route parameter requirements #45528
Conversation
5a0001f
to
299ac1c
Compare
98ade84
to
019c4d3
Compare
Now i'm wondering ... when by default (any format allowed) can we me make the canonical format also the canonical URL at HTTP level? https://developers.google.com/search/docs/advanced/crawling/consolidate-duplicate-urls |
2d7d85d
to
1530a42
Compare
I like the idea. Do we envision adding more "simple" requirements there? Like for integers, emails, ... My question is about what we want to have in this Requirement class. |
Also some date formats would be nice as they're common in URLs. |
I think that
is not enough, I think that there should be also patterns for specific versions of UUID and not just generic one. |
What about a slug pattern? |
To complement the slug pattern, there's
|
The validator component contains some regex that can be useful in URL matching. Is it worth adding them?
public const PATTERN = '/^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/'; |
public const PATTERN = '/^(\d{2}):(\d{2}):(\d{2})$/'; |
public const VALIDATION_PATTERN = '/[A-Z]{2}[A-Z0-9]{9}[0-9]{1}/'; |
Thank you all for the complementary proposals. What about merging as is and iterate by sending PRs?
I'd rather wait for more requirements to be implemented. As is, this is of limited value. Announcing a well-thought feature is better IMHO. |
I moved the enum to the
Not sure adding simple cases like
Y-m-d and H:i:s?
We can add several regexes but can we fully validate all versions just with a regex? I'm not sure, @nicolas-grekas?
Slugs can be very different depending on the application IMHO but we can add one very generic case like [a-zA-Z0-9-]+ but does it really bring value? |
It should be possible to validate the version of a UUID using a regexp yes. |
See https://stackoverflow.com/questions/136505/searching-for-uuids-in-text-with-regex which gives a stricter regexp even for generic UUIDs. |
a612206
to
5571b8c
Compare
Wow, what a great PR.
If you add \d+
then it would cover all needs that I have in my application.
At some few scenarios, I've used .*
if I wanted to catch everything including slashes (/
). Ie "redirect to legacy app controller".
EDIT: Use .+
would make more sense.
.+
- Catch everything
.*
- Catch everything including empty string
Agree, I use this quite a lot but as Lots of questions on stackoverflow about this. |
Tests looks broken |
I'll add some tests for every regex, do you think we have reached the first iteration of the set that will be merged? |
Looks like a good first set. |
269192f
to
73af741
Compare
…on constants to use as route parameter requirements
Thank you @fancyweb. |
Ref #44665.
We need a way to easily reference some universal complicated regexes in routes parameters requirements, for example:
What about having a collection in the routing component itself? I'm sure there are other common cases we would add here.