Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

safety, url: skip handling invalid links with empty hostnames #2472

Merged
merged 2 commits into from
Jun 17, 2023
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
2 changes: 1 addition & 1 deletion sopel/modules/safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def url_handler(bot: SopelWrapper, trigger: Trigger):

try:
hostname = urlparse(url).hostname.lower()
except ValueError:
except (ValueError, AttributeError):
pass # Invalid address
else:
if any(regex.search(hostname) for regex in known_good):
Expand Down
3 changes: 2 additions & 1 deletion sopel/modules/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ def title_auto(bot: SopelWrapper, trigger: Trigger):
# Avoid fetching known malicious links
if url in safety_cache and safety_cache[url]["positives"] > 0:
continue
if urlparse(url).hostname.lower() in safety_cache_local:
parsed = urlparse(url)
if not parsed.hostname or parsed.hostname.lower() in safety_cache_local:
continue
urls.append(url)

Expand Down