Skip to content

Commit 0214848

Browse files
committed
Fix URL handling to prevent /wiki/wiki duplication in Confluence client
1 parent b1f313e commit 0214848

File tree

2 files changed

+146
-567
lines changed

2 files changed

+146
-567
lines changed

atlassian/confluence/base.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,22 @@ def __init__(
160160
args: Arguments to pass to AtlassianRestAPI constructor
161161
kwargs: Keyword arguments to pass to AtlassianRestAPI constructor
162162
"""
163-
if self._is_cloud_url(url) and "/wiki" not in url:
164-
url = AtlassianRestAPI.url_joiner(url, "/wiki")
163+
# Handle the URL correctly for Confluence Cloud
164+
if self._is_cloud_url(url):
165+
# Strip any trailing '/wiki' from the URL
166+
if url.rstrip('/').endswith('/wiki'):
167+
url = url.rstrip('/')[:-5]
168+
169+
# Set cloud flag
165170
if "cloud" not in kwargs:
166171
kwargs["cloud"] = True
167172

173+
# Add "/wiki" to the URL only if it's truly not present in any part
174+
parsed_url = urlparse(url)
175+
path_parts = parsed_url.path.split('/')
176+
if 'wiki' not in path_parts:
177+
url = AtlassianRestAPI.url_joiner(url, "/wiki")
178+
168179
super(ConfluenceBase, self).__init__(url, *args, **kwargs)
169180
self.api_version = int(api_version)
170181
if self.api_version not in [1, 2]:
@@ -289,10 +300,18 @@ def _get_paged(
289300
base_url = response.get("_links", {}).get("base")
290301
if base_url and next_url.startswith('/'):
291302
# Construct the full URL using the base URL from the response
292-
url = f"{base_url}{next_url}"
303+
# Check for and prevent /wiki/wiki duplication
304+
if base_url.endswith('/wiki') and next_url.startswith('/wiki/'):
305+
url = f"{base_url}{next_url[5:]}" # Strip the duplicate /wiki
306+
else:
307+
url = f"{base_url}{next_url}"
293308
absolute = True
294309
else:
310+
# Check for and prevent /wiki/wiki duplication in the URL
311+
if '/wiki/wiki/' in next_url:
312+
next_url = next_url.replace('/wiki/wiki/', '/wiki/')
295313
url = next_url
314+
296315
# Check if the URL is absolute (has http:// or https://) or contains the server's domain
297316
if next_url.startswith(('http://', 'https://')) or self.url.split('/')[2] in next_url:
298317
absolute = True

0 commit comments

Comments
 (0)