-
-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
safety: fix safeify_url() exception on python 3.11
- Loading branch information
1 parent
e7d8648
commit d3b0cf4
Showing
2 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Tests for Sopel's ``safety`` plugin""" | ||
|
||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from sopel.builtins.safety import safeify_url | ||
|
||
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/"), | ||
# Invalid, but parsed anyway | ||
("http://<Target-IP>/", "hxxp://<Target-IP>/"), | ||
("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[:][:][:]]/"), | ||
) | ||
|
||
|
||
@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) |