safety: safeify_url()
function can't handle (invalid) URLs with [hostname]
placeholder
#2644
Labels
Bug
Things to squish; generally used for issues
If someone sends a link while
safety
is active in the channel, and the URL contains a placeholder hostname in square brackets, Sopel will spit out an "Unexpected ValueError" message. Note: Seems to happen only on Python 3.11 or higher.This is from the
safeify_url()
function added in #2279, which usesurllib.parse.urlparse()
to make sanitizing URL parts easier, which in turn usesipaddress.ip_address()
to raise an error for bracketed IPv4 addresses—and trips on this weird edge case:sopel/sopel/builtins/safety.py
Lines 127 to 133 in e7d8648
Simple examples using the Python console:
The version inconsistency is going to be the worst part of designing a "correct" fix for this. A simple fallback approach (such as
return url.replace('http', 'hxxp', 1) if url.startswith('http') else url
) will miss more complicated cases that are still handled fine in older Python versions (output using 3.10 shown here):Do note though that all this is an edge case of an edge case. People must intentionally construct these invalid URLs, and can be trained to simply use another type of bracket for placeholders instead, such as
http://<Target-IP>/cgi-bin/account_mgr.cgi
.The text was updated successfully, but these errors were encountered: