mirror of https://github.com/caronc/apprise
Improved CLI parsing; now support keywords containing URLs (#241)
parent
73046207d5
commit
aac8455a5f
|
@ -120,7 +120,7 @@ GET_PHONE_NO_RE = re.compile(r'^\+?(?P<phone>[0-9\s)(+-]+)\s*$')
|
||||||
|
|
||||||
# Regular expression used to destinguish between multiple URLs
|
# Regular expression used to destinguish between multiple URLs
|
||||||
URL_DETECTION_RE = re.compile(
|
URL_DETECTION_RE = re.compile(
|
||||||
r'([a-z0-9]+?:\/\/.*?)[\s,]*(?=$|[a-z0-9]+?:\/\/)', re.I)
|
r'([a-z0-9]+?:\/\/.*?)(?=$|[\s,]+[a-z0-9]{2,9}?:\/\/)', re.I)
|
||||||
|
|
||||||
# validate_regex() utilizes this mapping to track and re-use pre-complied
|
# validate_regex() utilizes this mapping to track and re-use pre-complied
|
||||||
# regular expressions
|
# regular expressions
|
||||||
|
@ -482,13 +482,6 @@ def split_urls(urls):
|
||||||
except TypeError:
|
except TypeError:
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
if len(results) > 0 and results[len(results) - 1][-1] != urls[-1]:
|
|
||||||
# we always want to save the end of url URL if we can; This handles
|
|
||||||
# cases where there is actually a comma (,) at the end of a single URL
|
|
||||||
# that would have otherwise got lost when our regex passed over it.
|
|
||||||
results[len(results) - 1] += \
|
|
||||||
re.match(r'.*?([\s,]+)?$', urls).group(1).rstrip()
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -542,6 +542,12 @@ def test_split_urls():
|
||||||
assert 'windows://' in results
|
assert 'windows://' in results
|
||||||
assert 'gnome://' in results
|
assert 'gnome://' in results
|
||||||
|
|
||||||
|
# We don't want to parse out URLs that are part of another URL's arguments
|
||||||
|
results = utils.split_urls('discord://host?url=https://localhost')
|
||||||
|
assert isinstance(results, list)
|
||||||
|
assert len(results) == 1
|
||||||
|
assert 'discord://host?url=https://localhost' in results
|
||||||
|
|
||||||
# Commas and spaces found inside URLs are ignored
|
# Commas and spaces found inside URLs are ignored
|
||||||
urls = [
|
urls = [
|
||||||
'mailgun://noreply@sandbox.mailgun.org/apikey/?to=test@example.com,'
|
'mailgun://noreply@sandbox.mailgun.org/apikey/?to=test@example.com,'
|
||||||
|
|
Loading…
Reference in New Issue