Skip to content

Commit aa62ff2

Browse files
committed
Removing the regexp. It can not handle localhost and special TLDs
1 parent af04a2c commit aa62ff2

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

rethinkdb/helpers.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def chain_to_bytes(*strings):
1414

1515

1616
def get_hostname_for_ssl_match(hostname):
17-
match = re.match(r'^((?P<subdomain>[^\.]+)\.)?(?P<domain>[^\./]+\.[^/]+)/?.*$', hostname)
18-
domain = match.group('domain')
19-
return '*.{domain}'.format(domain=domain) if match.group('subdomain') else domain
17+
parts = hostname.split('.')
18+
19+
if len(parts) < 3:
20+
return hostname
21+
22+
parts[0] = '*'
23+
return '.'.join(parts)

tests/test_helpers.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,23 @@ def test_subdomain_replaced_to_star(self):
5353

5454
assert result == expected_string
5555

56+
def test_subdomain_replaced_to_star_special_tld(self):
57+
expected_string = '*.example.co.uk'
58+
59+
result = get_hostname_for_ssl_match('test.example.co.uk')
60+
61+
assert result == expected_string
62+
5663
def test_no_subdomain_to_replace(self):
5764
expected_string = 'example.com'
5865

59-
result = get_hostname_for_ssl_match('example.com')
66+
result = get_hostname_for_ssl_match(expected_string)
6067

6168
assert result == expected_string
6269

63-
def test_no_match(self):
64-
with pytest.raises(AttributeError) as exc:
65-
get_hostname_for_ssl_match('')
70+
def test_no_tld(self):
71+
expected_string = 'localhost'
72+
73+
result = get_hostname_for_ssl_match(expected_string)
74+
75+
assert result == expected_string

0 commit comments

Comments
 (0)