-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Use str as default path converter #9066
Conversation
@@ -144,7 +144,7 @@ def __init__(self, trailing_slash=True, use_regex_path=True): | |||
self._url_conf = re_path | |||
else: | |||
self._base_pattern = '<{lookup_value}:{lookup_prefix}{lookup_url_kwarg}>' | |||
self._default_value_pattern = 'path' | |||
self._default_value_pattern = 'str' |
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.
any tests to verify this?
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.
Here they are: I have added the corner case in which there may be some patterns which may be ambigouus.
Thus using the <path:var>
could cause problems, since it is too greedy, and having the latest registered pattern to never match if there is any sub-match.
str - Matches any non-empty string, excluding the path separator, '/'. This is the default if a converter isn’t included in the expression. can you weigh in a bit more in the context? |
Consider the test viewset The url-patterns produced by the router for this are going to be:
The second pattern with Since the router follows this sequence to build patterns:
The problem arises when there are both default detail and any action detail. Since the first pattern ( An other way to avoid such confusion would be to change the order of routes in As final note the We may also register a custom path converter for rest-framework to match the pattern |
Description
Improves #6789 by using
str
as default path converter instead ofpath
.This because re-reading the docs the more appropriate to use is
str
.This because its regex is
[^/]+
which, among converters, is the most similar to the default used by router ([^/.]+
).