File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -81,6 +81,15 @@ class Test404(TestCase):
8181 def test_legacy_path (self ):
8282 self .assertEqual (legacy_path ("/any/thing" ), "http://legacy.python.org/any/thing" )
8383
84+ def test_legacy_path_without_leading_slash (self ):
85+ self .assertEqual (legacy_path ("any/thing" ), "http://legacy.python.org/any/thing" )
86+
87+ def test_legacy_path_with_encoded_slash (self ):
88+ self .assertEqual (legacy_path ("/%2Fevil.test/x" ), "http://legacy.python.org/%2Fevil.test/x" )
89+
90+ def test_legacy_path_with_decoded_encoded_slash (self ):
91+ self .assertEqual (legacy_path ("//evil.test/x" ), "http://legacy.python.org//evil.test/x" )
92+
8493 def test_custom_404 (self ):
8594 """Ensure custom 404 is set to 5 minutes"""
8695 response = self .client .get ("/foo-bar/baz/9876" )
Original file line number Diff line number Diff line change 11"""Views for the cms app, including custom error handlers."""
22
3- from urllib .parse import urljoin
3+ from urllib .parse import quote
44
55from django .shortcuts import render
66from django .urls import reverse
1111
1212def legacy_path (path ):
1313 """Build a path to the same path under the legacy.python.org domain."""
14- return urljoin (LEGACY_PYTHON_DOMAIN , path )
14+ if not path .startswith ("/" ):
15+ path = f"/{ path } "
16+ return f"{ LEGACY_PYTHON_DOMAIN } { quote (path , safe = '/%' )} "
1517
1618
1719def custom_404 (request , exception , template_name = "404.html" ):
You can’t perform that action at this time.
0 commit comments