Skip to content

Commit

Permalink
Merge branch 'bugfix/incomplete-url-sanitization-3291' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
Taaku18 committed Nov 20, 2023
2 parents 5482e94 + 2b66710 commit dcdfb95
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 @@ -152,13 +152,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 dcdfb95

Please sign in to comment.