Skip to content

Commit

Permalink
Fix code scanning alert #5
Browse files Browse the repository at this point in the history
  • Loading branch information
raidensakura committed Dec 23, 2023
1 parent f0815a6 commit 2d995b7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,17 @@ def is_image_url(url: str, **kwargs) -> str:
bool
Whether the URL is a valid image URL.
"""
if url.startswith("https://gyazo.com") or url.startswith("http://gyazo.com"):
# gyazo support
url = re.sub(
r"(http[s]?:\/\/)((?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)",
r"\1i.\2.png",
url,
)
try:
result = parse.urlparse(url)
if result.netloc == "gyazo.com" and result.scheme in ["http", "https"]:
# gyazo support
url = re.sub(
r"(https?://)((?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|%[0-9a-fA-F][0-9a-fA-F])+)",
r"\1i.\2.png",
url,
)
except ValueError:
pass

return parse_image_url(url, **kwargs)

Expand Down

0 comments on commit 2d995b7

Please sign in to comment.