-
-
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
da05822
commit 8977dbe
Showing
2 changed files
with
38 additions
and
8 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,27 @@ | ||
"""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/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://<placeholder>/", ("hxxp://<placeholder>/")), | ||
("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 on these 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_options", URL_TESTS) | ||
def test_safeify_url(original, safed_options): | ||
assert safeify_url(original) in safed_options |