Skip to content

Commit 4d7a326

Browse files
authored
Merge pull request #26 from KostyaEsmukov/userinfo_allowed_chars
Fix some chars (!, =, etc) being treated as not allowed in userinfo of authority
2 parents 6b8e178 + c6b1492 commit 4d7a326

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/rfc3986/abnf_regexp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@
132132
IPv4_RE,
133133
IP_LITERAL_RE,
134134
)
135-
USERINFO_RE = '^[A-Za-z0-9_.~\-%:]+'
135+
USERINFO_RE = '^([' + UNRESERVED_RE + SUB_DELIMITERS_RE + ':]|%s)+' % (
136+
PCT_ENCODED
137+
)
136138
PORT_RE = '[0-9]{1,5}'
137139

138140
# ####################

tests/base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ def test_handles_uri_with_port_and_userinfo(
5858
assert uri.fragment is None
5959
assert uri.userinfo == 'user:pass'
6060

61+
def test_handles_tricky_userinfo(
62+
self, uri_with_port_and_tricky_userinfo):
63+
"""
64+
Test that self.test_class can handle a URI with unusual
65+
(non a-z) chars in userinfo.
66+
"""
67+
uri = self.test_class.from_string(uri_with_port_and_tricky_userinfo)
68+
assert uri.scheme == 'ssh'
69+
# 6 == len('ftp://')
70+
assert uri.authority == uri_with_port_and_tricky_userinfo[6:]
71+
assert uri.host != uri.authority
72+
assert str(uri.port) == '22'
73+
assert uri.path is None
74+
assert uri.query is None
75+
assert uri.fragment is None
76+
assert uri.userinfo == 'user%20!=:pass'
77+
6178
def test_handles_basic_uri_with_path(self, basic_uri_with_path):
6279
"""Test that self.test_class can handle a URI with a path."""
6380
uri = self.test_class.from_string(basic_uri_with_path)

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ def uri_with_port_and_userinfo(request):
8080
return 'ssh://user:pass@%s:22' % request.param
8181

8282

83+
@pytest.fixture(params=valid_hosts)
84+
def uri_with_port_and_tricky_userinfo(request):
85+
return 'ssh://%s@%s:22' % ('user%20!=:pass', request.param)
86+
87+
8388
@pytest.fixture(params=valid_hosts)
8489
def basic_uri_with_path(request):
8590
return 'http://%s/path/to/resource' % request.param

0 commit comments

Comments
 (0)