Skip to content

Commit

Permalink
Fix compatibility with Python 2.7 (#163)
Browse files Browse the repository at this point in the history
* Fix compatibility with Python 2.7

* changelog
  • Loading branch information
davisagli authored Oct 1, 2023
1 parent 0958370 commit d5dea80
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/162.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix compatibility with Python 2.7. @davisagli
4 changes: 2 additions & 2 deletions src/plone/rest/tests/test_traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_html_request_via_double_apis_raises_redirect(self):
self.traverse(path="/plone/++api++/++api++", accept="text/html")
self.assertEqual(
exc.exception.headers["Location"],
f"{portal_url}/++api++",
"{}/++api++".format(portal_url),
)

def test_html_request_via_multiple_apis_raises_redirect(self):
Expand All @@ -129,7 +129,7 @@ def test_html_request_via_multiple_apis_raises_redirect(self):
)
self.assertEqual(
exc.exception.headers["Location"],
f"{portal_url}/++api++/search",
"{}/++api++/search".format(portal_url),
)

def test_html_request_via_multiple_bad_apis_raises_not_found(self):
Expand Down
4 changes: 2 additions & 2 deletions src/plone/rest/traverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def traverse(self, name_ignored, subpath_ignored):
url = self.request.ACTUAL_URL
if url.count(name) > 1:
# Redirect to proper url.
while f"{name}{name}" in url:
url = url.replace(f"{name}{name}", name)
while name + name in url:
url = url.replace(name + name, name)
if url.count(name) > 1:
# Something like: .../++api++/something/++api++
# Return nothing, so a NotFound is raised.
Expand Down

0 comments on commit d5dea80

Please sign in to comment.