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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Only change where path is used
stsewd committed Apr 15, 2020

Verified

This commit was signed with the committer’s verified signature.
snyk-bot Snyk bot
commit 0e946d9ea5e84170ba13816d6456be2eebdcf9dd
7 changes: 3 additions & 4 deletions readthedocs/proxito/views/serve.py
Original file line number Diff line number Diff line change
@@ -210,7 +210,7 @@ def get(self, request, proxito_path, template_name='404.html'):

# First, check for dirhtml with slash
for tryfile in ('index.html', 'README.html'):
storage_filename_path = f'{storage_root_path}/{filename}/{tryfile}'
storage_filename_path = f'{storage_root_path}/' + filename.strip('/') + f'/{tryfile}'
log.debug(
'Trying index filename: project=%s version=%s, file=%s',
final_project.slug,
@@ -226,11 +226,10 @@ def get(self, request, proxito_path, template_name='404.html'):
)
# Use urlparse so that we maintain GET args in our redirect
parts = urlparse(proxito_path)
path = parts.path.rstrip('/')
if tryfile == 'README.html':
new_path = f'{path}/{tryfile}'
new_path = parts.path.rstrip('/') + f'/{tryfile}'
else:
new_path = path + '/'
new_path = parts.path.rstrip('/') + '/'
new_parts = parts._replace(path=new_path)
redirect_url = new_parts.geturl()

3 changes: 1 addition & 2 deletions readthedocs/proxito/views/utils.py
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ def _get_project_data_from_request(
# Handle single-version projects that have URLs like a real project
if current_project.single_version:
if lang_slug and version_slug:
filename = f'{lang_slug}/{version_slug}/{filename}'
filename = os.path.join(lang_slug, version_slug, filename)
log.warning(
'URL looks like versioned on a single version project.'
'Changing filename to match. filename=%s',
@@ -85,5 +85,4 @@ def _get_project_data_from_request(
# * Subproject
# * Translations

filename = filename.rstrip('/')
return final_project, lang_slug, version_slug, filename