Skip to content
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
14 changes: 4 additions & 10 deletions apiserver/plane/bgtasks/copy_s3_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import base64
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin

# Django imports
from django.conf import settings

Expand All @@ -12,7 +12,7 @@
from plane.utils.exception_logger import log_exception
from plane.settings.storage import S3Storage
from celery import shared_task
from plane.utils.url import get_url_components
from plane.utils.url import normalize_url_path


def get_entity_id_field(entity_type, entity_id):
Expand Down Expand Up @@ -69,17 +69,11 @@ def sync_with_external_service(entity_name, description_html):
"variant": "rich" if entity_name == "PAGE" else "document",
}

if not settings.LIVE_URL:
return {}

live_url = get_url_components(settings.LIVE_URL)
live_url = settings.LIVE_URL
if not live_url:
return {}

base_url = (
f"{live_url.get('scheme')}://{live_url.get('netloc')}{live_url.get('path')}"
)
url = urljoin(base_url, "convert-document/")
url = normalize_url_path(f"{live_url}/convert-document/")

response = requests.post(url, json=data, headers=None)
if response.status_code == 200:
Expand Down
27 changes: 26 additions & 1 deletion apiserver/plane/utils/url.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Python imports
import re
from typing import Optional
from urllib.parse import urlparse
from urllib.parse import urlparse, urlunparse


def is_valid_url(url: str) -> bool:
Expand Down Expand Up @@ -52,3 +53,27 @@ def get_url_components(url: str) -> Optional[dict]:
"query": result.query,
"fragment": result.fragment,
}


def normalize_url_path(url: str) -> str:
"""
Normalize the path component of a URL by replacing multiple consecutive slashes with a single slash.

This function preserves the protocol, domain, query parameters, and fragments of the URL,
only modifying the path portion to ensure there are no duplicate slashes.

Args:
url (str): The input URL string to normalize.

Returns:
str: The normalized URL with redundant slashes in the path removed.

Example:
>>> normalize_url_path('https://example.com//foo///bar//baz?x=1#frag')
'https://example.com/foo/bar/baz?x=1#frag'
"""
parts = urlparse(url)
# Normalize the path
normalized_path = re.sub(r"/+", "/", parts.path)
# Reconstruct the URL
return urlunparse(parts._replace(path=normalized_path))