@@ -160,11 +160,22 @@ def __init__(
160
160
args: Arguments to pass to AtlassianRestAPI constructor
161
161
kwargs: Keyword arguments to pass to AtlassianRestAPI constructor
162
162
"""
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
165
170
if "cloud" not in kwargs :
166
171
kwargs ["cloud" ] = True
167
172
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
+
168
179
super (ConfluenceBase , self ).__init__ (url , * args , ** kwargs )
169
180
self .api_version = int (api_version )
170
181
if self .api_version not in [1 , 2 ]:
@@ -289,10 +300,18 @@ def _get_paged(
289
300
base_url = response .get ("_links" , {}).get ("base" )
290
301
if base_url and next_url .startswith ('/' ):
291
302
# 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 } "
293
308
absolute = True
294
309
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/' )
295
313
url = next_url
314
+
296
315
# Check if the URL is absolute (has http:// or https://) or contains the server's domain
297
316
if next_url .startswith (('http://' , 'https://' )) or self .url .split ('/' )[2 ] in next_url :
298
317
absolute = True
0 commit comments