Skip to content

Commit

Permalink
fixed userinfo regex for @ character in userinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
can committed Sep 10, 2019
1 parent 2982509 commit 4ae4903
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/rfc3986/abnf_regexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@
IPv4_RE,
IP_LITERAL_RE,
)
USERINFO_RE = '^([' + UNRESERVED_RE + SUB_DELIMITERS_RE + ':]|%s)+' % (
PCT_ENCODED
USERINFO_RE = '^([%s%s:]|%s)+.*(?=@)' % (
UNRESERVED_RE, SUB_DELIMITERS_RE, PCT_ENCODED
)
PORT_RE = '[0-9]{1,5}'

Expand Down Expand Up @@ -241,8 +241,8 @@
IP_LITERAL_RE,
)

IUSERINFO_RE = u'^(?:[' + IUNRESERVED_RE + SUB_DELIMITERS_RE + u':]|%s)+' % (
PCT_ENCODED
IUSERINFO_RE = u'^(?:[%s%s:]|%s)+.*(?=@)' % (
IUNRESERVED_RE, SUB_DELIMITERS_RE, PCT_ENCODED
)

IFRAGMENT_RE = (u'^(?:[/?:@' + IUNRESERVED_RE + SUB_DELIMITERS_RE
Expand Down
20 changes: 20 additions & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ def test_handles_uri_with_port_and_userinfo(
assert uri.fragment is None
assert uri.userinfo == 'user:pass'

def test_handles_uri_with_email_userinfo(
self, uri_with_email_userinfo):
"""
Test that self.test_class can handle a URI with a port and userinfo.
"""
uri = self.test_class.from_string(uri_with_email_userinfo)
assert uri.scheme == 'ssh'
# 6 == len('ftp://')
assert uri.authority == uri_with_email_userinfo[6:]
assert uri.host != uri.authority
assert uri.path is None
assert uri.query is None
assert uri.fragment is None
assert uri.userinfo == '[email protected]:pass'

def test_handles_tricky_userinfo(
self, uri_with_port_and_tricky_userinfo):
"""
Expand Down Expand Up @@ -150,6 +165,11 @@ def test_uri_with_port_and_userinfo_unsplits(self,
uri = self.test_class.from_string(uri_with_port_and_userinfo)
assert uri.unsplit() == uri_with_port_and_userinfo

def test_uri_with_email_userinfo_unsplits(self,
uri_with_email_userinfo):
uri = self.test_class.from_string(uri_with_email_userinfo)
assert uri.unsplit() == uri_with_email_userinfo

def test_basic_uri_with_path_unsplits(self, basic_uri_with_path):
uri = self.test_class.from_string(basic_uri_with_path)
assert uri.unsplit() == basic_uri_with_path
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def basic_uri_with_port(request):
def uri_with_port_and_userinfo(request):
return 'ssh://user:pass@%s:22' % request.param

@pytest.fixture(params=valid_hosts)
def uri_with_email_userinfo(request):
return 'ssh://[email protected]:pass@%s' % request.param


@pytest.fixture(params=valid_hosts)
def uri_with_port_and_tricky_userinfo(request):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ def test_uri_with_port_and_userinfo_is_valid(self,
uri = URIReference.from_string(uri_with_port_and_userinfo)
assert uri.is_valid() is True

def test_uri_with_email_userinfo_is_valid(self,
uri_with_email_userinfo):
uri = URIReference.from_string(uri_with_email_userinfo)
assert uri.is_valid() is True

def test_basic_uri_with_path_is_valid(self, basic_uri_with_path):
uri = URIReference.from_string(basic_uri_with_path)
assert uri.is_valid() is True
Expand Down Expand Up @@ -166,6 +171,10 @@ def test_uri_with_port_and_userinfo(self, uri_with_port_and_userinfo):
uri = URIReference.from_string(uri_with_port_and_userinfo)
assert uri == uri_with_port_and_userinfo

def test_uri_with_email_userinfo(self, uri_with_email_userinfo):
uri = URIReference.from_string(uri_with_email_userinfo)
assert uri == uri_with_email_userinfo

def test_basic_uri_with_path(self, basic_uri_with_path):
uri = URIReference.from_string(basic_uri_with_path)
assert uri == basic_uri_with_path
Expand Down Expand Up @@ -207,6 +216,10 @@ def test_uri_with_port_and_userinfo(self, uri_with_port_and_userinfo):
uri = URIReference.from_string(uri_with_port_and_userinfo)
assert uri == self.to_tuple(uri_with_port_and_userinfo)

def test_uri_with_email_userinfo(self, uri_with_email_userinfo):
uri = URIReference.from_string(uri_with_email_userinfo)
assert uri == self.to_tuple(uri_with_email_userinfo)

def test_basic_uri_with_path(self, basic_uri_with_path):
uri = URIReference.from_string(basic_uri_with_path)
assert uri == self.to_tuple(basic_uri_with_path)
Expand Down

0 comments on commit 4ae4903

Please sign in to comment.