Skip to content

Commit

Permalink
Improved hostname verification (#1243)
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc authored Nov 20, 2024
1 parent f37dfbf commit 5441c15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apprise/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def is_hostname(hostname, ipv4=True, ipv6=True, underscore=True):
labels = hostname.split(".")

# ipv4 check
if len(labels) == 4 and re.match(r'[0-9.]+', hostname):
if len(labels) == 4 and re.match(r'^[0-9.]+$', hostname):
return is_ipaddr(hostname, ipv4=ipv4, ipv6=False)

# - RFC 1123 permits hostname labels to start with digits
Expand Down
16 changes: 16 additions & 0 deletions test/test_apprise_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ def test_parse_url_general():
assert result['qsd+'] == {}
assert result['qsd:'] == {}

# GitHub Ticket 1234 - Unparseable Hostname
result = utils.parse_url('http://5t4m59hl-34343.euw.devtunnels.ms')
assert result['schema'] == 'http'
assert result['host'] == '5t4m59hl-34343.euw.devtunnels.ms'
assert result['port'] is None
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] is None
assert result['path'] is None
assert result['query'] is None
assert result['url'] == 'http://5t4m59hl-34343.euw.devtunnels.ms'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
assert result['qsd:'] == {}

result = utils.parse_url('http://hostname/')
assert result['schema'] == 'http'
assert result['host'] == 'hostname'
Expand Down

0 comments on commit 5441c15

Please sign in to comment.