-
-
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
Backslashes added to paths at docs from include_docs_urls
#5675
Comments
include_docs_urls
Downgrading to Django 1.11 fixed the problem. Would |
In Django 2, routes defines via urls.path are aggresively escaped when converted into regex. This is a naive fix which unescapes all characters outside capture groups, but in the context of OpenAPI is okay because regular expressions inside paths are not supported anyway. This issue affects django-rest-framework as well, as outlined in encode/django-rest-framework#5672, encode/django-rest-framework#5675.
More specifically, I think this should be addressed by Django in r"""
Clean up urlpattern regexes into something more readable by humans. For
example, turn "^(?P<sport_slug>\w+)/athletes/(?P<athlete_slug>\w+)/$"
into "/<sport_slug>/athletes/<athlete_slug>/".
""" get_path_from_regex in drf makes use of that function. I filed a bug in their tracker - https://code.djangoproject.com/ticket/28936 |
Good follow-up @axnsan12. Thanks. |
Thanks, if it is not fixed by next week I will try to submit a patch for |
Note: Discussion on #5686 has details worth viewing. |
I think one should do The bigger problem here seems not the escaping (can be dealt with calling Before in Django 1.x, the output of |
@tiltec I +1 your assessment. Calling Django 1.11 is the last version supporting 2.7 but it is an LTS version and support ends only in April 2020. |
Seems only tangentially related, but I wonder if there's a bug in Django 2.0 when using (EDIT) Upstream bug filed: https://code.djangoproject.com/ticket/28947 |
I encountered a follow-up bug. DRF uses uritemplate to parse the URL variables, but unfortunately the colon means something else there. RFC 6570 says that Doesn't really fit Maybe it's easiest to strip the converter part out for SchemaGenerator purposes? |
I think the converter part could be useful for the typing information it could provide about the path parameter. Perhaps the most complete solution would be to try and parse it just like django does? EDIT: or strip it and use the already parsed |
- Call `str(pattern)` to get non-escaped route - Strip converters from path to comply with uritemplate format Fixes encode#5675
- Call `str(pattern)` to get non-escaped route - Strip converters from path to comply with uritemplate format Fixes encode#5675
- Call `str(pattern)` to get non-escaped route - Strip converters from path to comply with uritemplate format Fixes encode#5675
3.7.4 will go tomorrow. I don’t know if a PR could be incoming by then, but it would make a great addition for the holidays if it could. 🙂 |
@carltongibson PR is ready, I could work on it a bit more today if needed 😄 |
Ah, good work @tiltec! I will review tomorrow AM. If others could comment that would help too! |
* Fix url parsing in schema generation - Call `str(pattern)` to get non-escaped route - Strip converters from path to comply with uritemplate format. Background: #5675 (comment) Fixes #5675
* Fix url parsing in schema generation - Call `str(pattern)` to get non-escaped route - Strip converters from path to comply with uritemplate format. Background: encode#5675 (comment) Fixes encode#5675
Checklist
master
branch of Django REST framework.Steps to reproduce
Using DRF installed from github, Django 2.0.
Included the following at
urls.py
:Expected behavior
Urls in docs should
api/endpoint-name/
Actual behavior
Urls are
api\/endpoint\-name/
, when using the "interact" button you get a 404 (request URL is/api%5C/profiles/
)The text was updated successfully, but these errors were encountered: