-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Handle paths with trailing /
#6906
Conversation
readthedocs/proxito/views/utils.py
Outdated
@@ -85,4 +85,5 @@ def _get_project_data_from_request( | |||
# * Subproject | |||
# * Translations | |||
|
|||
filename = filename.rstrip('/') |
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.
This seems hacky -- why are we doing this here?
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.
the slash gets captured in
r'^_proxito_404_(?P<proxito_path>.*)$', |
and it can end up with a slash in
filename = f'{lang_slug}/{version_slug}/{filename}' |
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.
We should attempt to fix that closer to where it's happening then. Perhaps os.path.join
was the proper logic after all?
We are calling this function a lot of places, and I don't want to put the logic here because it might cause other unintended issues.
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.
os.path.join depends on the running OS to add /
or \
, it could also happen to add an extra /
if it thinks it's a directory or the root. Changed to just strip the file before concatenate it.
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.
We have been hitting these kind of issues a lot when manipulating URLs, do you think that using a 3rd party library and follow the same pattern everywhere (*) in our code could help us?
3rd party package example: https://github.com/homm/yurl/
(*) do not use os.path.join
, nor "...".format()
nor "..." + "..."
etc, that we have mixtures of all of them --and use a package like this intead
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.
Looks like doesn't work like we want
>>> print(yurl.URL('foo/bar') + yurl.URL('bar'))
foo/bar
>>> print(yurl.URL('foo') + yurl.URL('bar'))
bar
>>> print(yurl.URL('foo/') + yurl.URL('bar'))
foo/bar
>>> print(yurl.URL('foo/') + yurl.URL('/bar'))
/bar
I think we could just write a little function to handle it.
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.
Yeah. I haven't tried that particular one, but there are many similar to this one.
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.
This looks like a better fix, at least for the current bug 👍
No description provided.