diff --git a/sopel/builtins/safety.py b/sopel/builtins/safety.py index f126538af..73ed3622a 100644 --- a/sopel/builtins/safety.py +++ b/sopel/builtins/safety.py @@ -263,11 +263,10 @@ def url_handler(bot: SopelWrapper, trigger: Trigger) -> None: safe_url, ) bot.say( - "{} {} of {} engine{} flagged a link {} posted as malicious".format( + "{} {} of {} engines flagged a link {} posted as malicious".format( bold(color("WARNING:", colors.RED)), positives, total, - "" if total == 1 else "s", bold(trigger.nick), ) ) diff --git a/test/builtins/test_builtins_safety.py b/test/builtins/test_builtins_safety.py index c076e793a..77bcc5e31 100644 --- a/test/builtins/test_builtins_safety.py +++ b/test/builtins/test_builtins_safety.py @@ -8,28 +8,20 @@ URL_TESTS = ( # Valid URLs - ("http://example.com", "hxxp://example[.]com"), - ("http://1.2.3.4/", "hxxp://1[.]2[.]3[.]4/"), - ("http://[fd00:1234::4321]/", "hxxp://[fd00[:]1234[:][:]4321]/"), - ("ftp://1.2.3.4/", "fxp://1[.]2[.]3[.]4/"), + ("http://example.com", ("hxxp://example[.]com")), + ("http://1.2.3.4/mgr.cgi", ("hxxp://1[.]2[.]3[.]4/mgr.cgi")), + ("http://[fd00:1234::4321]/", ("hxxp://[fd00[:]1234[:][:]4321]/")), + ("ftp://1.2.3.4/", ("fxp://1[.]2[.]3[.]4/")), # Invalid, but parsed anyway - ("http:///", "hxxp:///"), - ("http://1.2.3.4.5/", "hxxp://1[.]2[.]3[.]4[.]5/"), - ("http://555.555.555.555/", "hxxp://555[.]555[.]555[.]555/"), - # Fallback path - ("http://[fd00:::]/", "http[:]//[fd00[:][:][:]]/"), + ("http:///", ("hxxp:///")), + ("http://1.2.3.4.5/", ("hxxp://1[.]2[.]3[.]4[.]5/")), + ("http://555.555.555.555/", ("hxxp://555[.]555[.]555[.]555/")), + # urllib.urlparse() works in python <=3.10 but fails in 3.11 + ("http://[fd00:::]/", ("hxxp://[fd00[:][:][:]]/", "http[:]//[fd00[:][:][:]]/")), + ("http://[placeholder]/", ("hxxp://[placeholder]/", "http[:]//[placeholder]/")), ) -@pytest.mark.parametrize("original, safed", URL_TESTS) -def test_safeify_url(original, safed): - assert safeify_url(original) == safed - - -def test_safeify_maybe_parsefail(): - # Parse succeeds in python <=3.10 but fails in 3.11 - original = "http://[Target-IP]/account_mgr.cgi" - parseok = "hxxp://[Target-IP]/account_mgr.cgi" - parsefail = "http[:]//[Target-IP]/account_mgr[.]cgi" - - assert safeify_url(original) in (parseok, parsefail) +@pytest.mark.parametrize("original, safed_options", URL_TESTS) +def test_safeify_url(original, safed_options): + assert safeify_url(original) in safed_options