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

Fix compatibility with Python 2.7 #163

Merged
merged 2 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading