Skip to content
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

Merged
merged 2 commits into from Apr 15, 2020
Merged

Handle paths with trailing / #6906

merged 2 commits into from Apr 15, 2020

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Apr 14, 2020

No description provided.

@@ -85,4 +85,5 @@ def _get_project_data_from_request(
# * Subproject
# * Translations

filename = filename.rstrip('/')
Copy link
Member

@ericholscher ericholscher Apr 14, 2020

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?

Copy link
Member Author

@stsewd stsewd Apr 14, 2020

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}'

Copy link
Member

@ericholscher ericholscher Apr 14, 2020

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.

Copy link
Member Author

@stsewd stsewd Apr 15, 2020

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.

Copy link
Member

@humitos humitos Apr 15, 2020

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

Copy link
Member Author

@stsewd stsewd Apr 15, 2020

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.

Copy link
Member

@humitos humitos Apr 15, 2020

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.

readthedocs/proxito/views/serve.py Outdated Show resolved Hide resolved
Copy link
Member

@ericholscher ericholscher left a comment

This looks like a better fix, at least for the current bug 👍

@stsewd stsewd merged commit 9dd29b1 into master Apr 15, 2020
2 checks passed
@stsewd stsewd deleted the fix-trailing-slash branch Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants