Skip to content

gh-137146: Restrict IPvFuture address parsing to RFC 3986-valid characters #137147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
gh-137146: Add tests on IPvFuture
  • Loading branch information
mauricelambert authored Jul 28, 2025
commit 0f0cc9ba24c8fb7fb89265ba534f4bad173f3f00
12 changes: 12 additions & 0 deletions Lib/test/test_urlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest
import urllib.parse
from test import support
from strings import ascii_letters, digits

RFC1808_BASE = "http://a/b/c/d;p?q#f"
RFC2396_BASE = "http://a/b/c/d;p?q"
Expand Down Expand Up @@ -1419,6 +1420,17 @@ def test_invalid_bracketed_hosts(self):
self.assertRaises(ValueError, urllib.parse.urlsplit, 'scheme://prefix]v6a.ip[suffix')
self.assertRaises(ValueError, urllib.parse.urlsplit, 'scheme://prefix]v6a.ip')
self.assertRaises(ValueError, urllib.parse.urlsplit, 'scheme://v6a.ip[suffix')
# unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
unreserved = ascii_letters + digits + "-" + "." + "_" + "~"
# sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
sub_delims = "!" + "$" + "&" + "'" + "(" + ")" + "*" + "+" + "," + ";" + "="
ipvfuture_authorized_characters = unreserved + sub_delims + ":"
removed_characters = "\t\n\r"
for character in range(256):
character = chr(character)
if character in ipvfuture_authorized_characters or character in removed_characters:
continue
self.assertRaises(ValueError, urllib.parse.urlsplit, f'scheme://[v7.invalid{character}invalid]/')

def test_splitting_bracketed_hosts(self):
p1 = urllib.parse.urlsplit('scheme://user@[v6a.ip]:1234/path?query')
Expand Down
Loading