mirror of
https://github.com/caronc/apprise.git
synced 2024-11-21 23:53:23 +01:00
Allow hostnames with underscores when parsing URLs (#324)
This commit is contained in:
parent
2c2722f61f
commit
fa05cfa81e
5
.gitignore
vendored
5
.gitignore
vendored
@ -67,3 +67,8 @@ target/
|
||||
|
||||
#PyCharm
|
||||
.idea
|
||||
|
||||
#PyDev (Eclipse)
|
||||
.project
|
||||
.pydevproject
|
||||
.settings
|
||||
|
@ -120,9 +120,9 @@ GET_EMAIL_RE = re.compile(
|
||||
r'(?P<email>(?P<userid>[a-z0-9$%=_~-]+'
|
||||
r'(?:\.[a-z0-9$%+=_~-]+)'
|
||||
r'*)@(?P<domain>('
|
||||
r'(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+'
|
||||
r'[a-z0-9](?:[a-z0-9-]*[a-z0-9]))|'
|
||||
r'[a-z0-9][a-z0-9-]{5,})))'
|
||||
r'(?:[a-z0-9](?:[a-z0-9_-]*[a-z0-9])?\.)+'
|
||||
r'[a-z0-9](?:[a-z0-9_-]*[a-z0-9]))|'
|
||||
r'[a-z0-9][a-z0-9_-]{5,})))'
|
||||
r'\s*>?', re.IGNORECASE)
|
||||
|
||||
# Regular expression used to extract a phone number
|
||||
@ -232,9 +232,12 @@ def is_hostname(hostname, ipv4=True, ipv6=True):
|
||||
# - Hostnames can ony be comprised of alpha-numeric characters and the
|
||||
# hyphen (-) character.
|
||||
# - Hostnames can not start with the hyphen (-) character.
|
||||
# - as a workaround for https://github.com/docker/compose/issues/229 to
|
||||
# being able to address services in other stacks, we also allow
|
||||
# underscores in hostnames
|
||||
# - labels can not exceed 63 characters
|
||||
allowed = re.compile(
|
||||
r'(?!-)[a-z0-9][a-z0-9-]{1,62}(?<!-)$',
|
||||
r'^[a-z0-9][a-z0-9_-]{1,62}(?<!-)$',
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
|
@ -532,6 +532,8 @@ def test_is_hostname():
|
||||
assert utils.is_hostname('yahoo.ca.') == 'yahoo.ca'
|
||||
assert utils.is_hostname('valid-dashes-in-host.ca') == \
|
||||
'valid-dashes-in-host.ca'
|
||||
assert utils.is_hostname('valid-underscores_in_host.ca') == \
|
||||
'valid-underscores_in_host.ca'
|
||||
|
||||
# Invalid Hostnames
|
||||
assert utils.is_hostname('-hostname.that.starts.with.a.dash') is False
|
||||
@ -539,7 +541,6 @@ def test_is_hostname():
|
||||
assert utils.is_hostname(' spaces ') is False
|
||||
assert utils.is_hostname(' ') is False
|
||||
assert utils.is_hostname('') is False
|
||||
assert utils.is_hostname('valid-underscores_in_host.ca') is False
|
||||
|
||||
# Valid IPv4 Addresses
|
||||
assert utils.is_hostname('127.0.0.1') == '127.0.0.1'
|
||||
@ -625,6 +626,14 @@ def test_is_email():
|
||||
assert 'test' == results['user']
|
||||
assert '' == results['label']
|
||||
|
||||
results = utils.is_email('test@my-valid_host.com')
|
||||
assert '' == results['name']
|
||||
assert 'test@my-valid_host.com' == results['email']
|
||||
assert 'test@my-valid_host.com' == results['full_email']
|
||||
assert 'my-valid_host.com' == results['domain']
|
||||
assert 'test' == results['user']
|
||||
assert '' == results['label']
|
||||
|
||||
results = utils.is_email('tag+test@gmail.com')
|
||||
assert '' == results['name']
|
||||
assert 'test@gmail.com' == results['email']
|
||||
|
Loading…
Reference in New Issue
Block a user