-
-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2646 from half-duplex/safety-invalid-urls
safety: fix safeify_url() exception on python 3.11
- Loading branch information
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 |
I didn't notice this excess blank line before merging. Not going to worry about it now; at some point, if we decide to care enough, we'll add a flake8 plugin/config to enforce better linebreak consistency and fix this then.