Skip to content

Commit 93bfef2

Browse files
committed
server: updated parse_cloudinary_url()
1 parent 28d6e55 commit 93bfef2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/apps/base/utils/cloudinary.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import re
22

3-
43
def parse_cloudinary_url(cloudinary_url: str) -> dict:
54
"""Example: CLOUDINARY_URL=cloudinary://<api_key>:<api_secret>@<cloud_name>"""
65

7-
pattern = re.compile(r"cloudinary://(\w+):(\w+)@(\w+)")
6+
# Regex to handle characters like hyphens, underscores, and others
7+
pattern = re.compile(r'cloudinary://([^:]+):([^@]+)@([^/]+)')
88
match = pattern.match(cloudinary_url)
99

10-
return {"CLOUD_NAME": match.group(3), "API_KEY": match.group(1), "API_SECRET": match.group(2)}
10+
# Check if match is None to avoid AttributeError
11+
if not match:
12+
raise ValueError("CLOUDINARY_URL format is incorrect")
13+
14+
return {
15+
'CLOUD_NAME': match.group(3),
16+
'API_KEY': match.group(1),
17+
'API_SECRET': match.group(2)
18+
}

0 commit comments

Comments
 (0)