From 5441c15a1e8f593528ef378c0ea88572e115a96b Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Wed, 20 Nov 2024 16:26:45 -0500 Subject: [PATCH] Improved hostname verification (#1243) --- apprise/utils.py | 2 +- test/test_apprise_utils.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apprise/utils.py b/apprise/utils.py index a45c6bbd..c536405e 100644 --- a/apprise/utils.py +++ b/apprise/utils.py @@ -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 diff --git a/test/test_apprise_utils.py b/test/test_apprise_utils.py index 17cd1b15..0e1f4e31 100644 --- a/test/test_apprise_utils.py +++ b/test/test_apprise_utils.py @@ -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'