-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] Add Requirement, a collection of universal regular-expressions constants to use as route parameter requirements #45528
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
5a0001f
to
299ac1c
Compare
299ac1c
to
4cfdec7
Compare
98ade84
to
019c4d3
Compare
019c4d3
to
d22a7bb
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
1530a42
to
41bb856
Compare
41bb856
to
3d16f29
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? |
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
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.
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. |
5571b8c
to
7a230c6
Compare
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
73af741
to
f49cb6a
Compare
Thank you @fancyweb. |
…ds and pagination (HeahDude) This PR was merged into the 6.2 branch. Discussion ---------- [Routing] Add `Requirement::POSITIVE_INT` for common ids and pagination | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #45528 | License | MIT | Doc PR | ~ I targeted 6.1 because it's not yet released, should I rebase onto 6.2? ping `@fancyweb` :) Commits ------- bea54e6 [Routing] Add `Requirement::POSITIVE_INT` for common ids and pagination
what about adding an Email regexp? I understand that not all emails can be covered by regexp but some basic ones could be created I think. https://stackoverflow.com/a/201378/11815081 - pretty good explanation about validating an email by regexp |
…rst (nicwortel) This PR was merged into the 6.1 branch. Discussion ---------- [Routing] Document the Requirement constants in routing.rst Fixes #16718 symfony/symfony#45528 by `@fancyweb` introduced the `Symfony\Component\Routing\Requirement\Requirement` enum in Symfony 6.1, as a solution for symfony/symfony#26524. It was blogged about in https://symfony.com/blog/new-in-symfony-6-1-improved-routing-requirements-and-utf-8-parameters, but I couldn't find it anywhere in the Routing documentation. This PR adds a small hint about the use of the `Requirement` enum for common route requirements:  I'm open for suggestions to further improve this. I decided to use a small info block instead without code examples, because it doesn't seem to be a big feature and I'm not sure how well it is supported across all configuration formats. Let me know if you would like to see some code examples. Commits ------- 571647d Document the Requirement constants in routing.rst
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.