Skip to content

Commit b500dde

Browse files
committed
Fix URLs like /projects/subproject from 404ing when they don't end with a slash
This was hit by users. You can test it here: https://docs.celeryproject.org/projects/kombu
1 parent 4fded8c commit b500dde

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

readthedocs/proxito/tests/test_full.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ def test_versioned_no_slash(self):
287287
response['location'], '/en/latest/',
288288
)
289289

290+
290291
@mock.patch('readthedocs.proxito.views.serve.get_storage_class')
291292
def test_directory_indexes_readme_serving(self, storage_mock):
292293
self.project.versions.update(active=True, built=True)

readthedocs/proxito/tests/test_redirects.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
)
1313
class RedirectTests(BaseDocServing):
1414

15+
def test_root_url_no_slash(self):
16+
r = self.client.get('', HTTP_HOST='project.dev.readthedocs.io')
17+
self.assertEqual(r.status_code, 302)
18+
self.assertEqual(
19+
r['Location'], 'https://project.dev.readthedocs.io/en/latest/',
20+
)
21+
1522
def test_root_url(self):
1623
r = self.client.get('/', HTTP_HOST='project.dev.readthedocs.io')
1724
self.assertEqual(r.status_code, 302)
@@ -26,6 +33,13 @@ def test_subproject_root_url(self):
2633
r['Location'], 'https://project.dev.readthedocs.io/projects/subproject/en/latest/',
2734
)
2835

36+
def test_subproject_root_url_no_slash(self):
37+
r = self.client.get('/projects/subproject', HTTP_HOST='project.dev.readthedocs.io')
38+
self.assertEqual(r.status_code, 302)
39+
self.assertEqual(
40+
r['Location'], 'https://project.dev.readthedocs.io/projects/subproject/en/latest/',
41+
)
42+
2943
def test_root_redirect_with_query_params(self):
3044
r = self.client.get('/?foo=bar', HTTP_HOST='project.dev.readthedocs.io')
3145
self.assertEqual(r.status_code, 302)

readthedocs/proxito/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
# (Sub)project single version
148148
url(
149149
(
150-
r'^(?:projects/(?P<subproject_slug>{project_slug})/)?'
150+
r'^(?:projects/(?P<subproject_slug>{project_slug})/?)?'
151151
r'(?P<filename>{filename_slug})$'.format(**pattern_opts)
152152
),
153153
ServeDocs.as_view(),

0 commit comments

Comments
 (0)