-
Notifications
You must be signed in to change notification settings - Fork 273
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
Url parsing mangles urls with parenthesis in regex #373
Comments
hi @janne-tervo!
we do not account for that i suppose. pretty sure that this is an illegal regex pattern written like that >>> import re
>>> re.compile(r'^jsi18n/(?P[a-z]{2}(-[a-z]{2})?)/$')
re.error: unknown extension ?P[ at position 9
>>> re.compile('^jsi18n/(?P<some_name>[a-z]{2}(-[a-z]{2})?)/$')
>>> # no error i would guess that making requests there would also fail, maybe even starting the server. |
Markdown bit me here. This gets mangled by spectacular url parsing: This does not get mangled: |
This is caused by: |
ahh now i get it. makes sense. |
replace still incorrect regex with parsing state machine. regex are not cut out for parenthesis counting.
turns out this was fixed once before (#168) but it was incomplete. i chose to write a parser for it and replace the old RE. i believe it would have been possible to construct a extended RE, but it would have been (imho) way more complicated with low readability. i hope this solution now is at least somewhat readable and more importantly correct. can you check if this works for you now? |
This commit fixes my issue. |
awesome! i love the regex package and use it myself. i briefly tried but was not able to get it right and as you said, adding deps is always problematic. if my solution turns out to be suboptimal, we can still switch to regex. |
i'll close this issue for now. feel free to circle back if you notice any problems. |
Describe the bug
Spectacular schema generation mangles urls with parenthesis in parameter patterns
To Reproduce
Add to url patterns:
url(r'^jsi18n/(?P[a-z]{2}(-[a-z]{2})?)/$', JavaScriptCatalog.as_view()),
Attempt to generate schema fails.
Expected behavior
Url regex patterns with parenthesis are parsed correctly.
The text was updated successfully, but these errors were encountered: