Skip to content

Commit

Permalink
Don't append '.html' to URLs containing fragments (#2319)
Browse files Browse the repository at this point in the history
Fixes #2287
  • Loading branch information
berkerpeksag authored and agjohnson committed Jul 18, 2016
1 parent 61840fc commit 6b345e5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions readthedocs/core/resolver.py
Expand Up @@ -195,6 +195,9 @@ def _fix_filename(self, project, filename):
path = "index.html#document-" + filename
elif project.documentation_type in ["sphinx_htmldir", "mkdocs"]:
path = filename + "/"
elif '#' in filename:
# do nothing if the filename contains URL fragments
path = filename
else:
path = filename + ".html"
else:
Expand Down
30 changes: 30 additions & 0 deletions readthedocs/rtd_tests/tests/test_redirects.py
Expand Up @@ -215,6 +215,36 @@ def test_redirect_htmldir(self):
r['Location'], 'http://pip.readthedocs.org/en/latest/faq/')


class CustomRedirectTests(TestCase):

@classmethod
def setUpTestData(cls):
cls.pip = Project.objects.create(**{
'repo_type': 'git',
'name': 'Pip',
'default_branch': '',
'project_url': 'http://pip.rtfd.org',
'repo': 'https://github.com/fail/sauce',
'default_version': LATEST,
'privacy_level': 'public',
'version_privacy_level': 'public',
'description': 'wat',
'documentation_type': 'sphinx',
})
Redirect.objects.create(
project=cls.pip,
redirect_type='page',
from_url='/install.html',
to_url='/install.html#custom-fragment',
)

def test_redirect_fragment(self):
redirect = Redirect.objects.get(project=self.pip)
path = redirect.get_redirect_path('/install.html')
expected_path = '/docs/pip/en/latest/install.html#custom-fragment'
self.assertEqual(path, expected_path)


@override_settings(PUBLIC_DOMAIN='readthedocs.org', USE_SUBDOMAIN=False)
class RedirectBuildTests(TestCase):
fixtures = ["eric", "test_data"]
Expand Down

0 comments on commit 6b345e5

Please sign in to comment.