mirror of
https://github.com/caronc/apprise.git
synced 2024-11-25 01:24:03 +01:00
Fix Zulip 401 when botname contains a dash (#581)
This commit is contained in:
parent
fd0cb3ffcc
commit
af2919fbb5
@ -63,10 +63,11 @@ from ..common import NotifyType
|
||||
from ..utils import parse_list
|
||||
from ..utils import validate_regex
|
||||
from ..utils import is_email
|
||||
from ..utils import remove_suffix
|
||||
from ..AppriseLocale import gettext_lazy as _
|
||||
|
||||
# A Valid Bot Name
|
||||
VALIDATE_BOTNAME = re.compile(r'(?P<name>[A-Z0-9_]{1,32})(-bot)?', re.I)
|
||||
VALIDATE_BOTNAME = re.compile(r'(?P<name>[A-Z0-9_-]{1,32})', re.I)
|
||||
|
||||
# Organization required as part of the API request
|
||||
VALIDATE_ORG = re.compile(
|
||||
@ -122,7 +123,7 @@ class NotifyZulip(NotifyBase):
|
||||
'botname': {
|
||||
'name': _('Bot Name'),
|
||||
'type': 'string',
|
||||
'regex': (r'^[A-Z0-9_]{1,32}(-bot)?$', 'i'),
|
||||
'regex': (r'^[A-Z0-9_-]{1,32}$', 'i'),
|
||||
},
|
||||
'organization': {
|
||||
'name': _('Organization'),
|
||||
@ -183,7 +184,9 @@ class NotifyZulip(NotifyBase):
|
||||
raise TypeError
|
||||
|
||||
# The botname
|
||||
self.botname = match.group('name')
|
||||
botname = match.group('name')
|
||||
botname = remove_suffix(botname, '-bot')
|
||||
self.botname = botname
|
||||
|
||||
except (TypeError, AttributeError):
|
||||
msg = 'The Zulip botname specified ({}) is invalid.'\
|
||||
|
@ -1379,3 +1379,10 @@ def apply_template(template, app_mode=TemplateType.RAW, **kwargs):
|
||||
# to drop the '{{' and '}}' surrounding our match so that we can
|
||||
# re-index it back into our list
|
||||
return mask_r.sub(lambda x: fn(kwargs[x.group()[2:-2].strip()]), template)
|
||||
|
||||
|
||||
def remove_suffix(value, suffix):
|
||||
"""
|
||||
Removes a suffix from the end of a string.
|
||||
"""
|
||||
return value[:-len(suffix)] if value.endswith(suffix) else value
|
||||
|
@ -55,6 +55,11 @@ apprise_url_tests = (
|
||||
('zulip://....@apprise/{}'.format('a' * 32), {
|
||||
'instance': TypeError,
|
||||
}),
|
||||
# Valid everything - botname with a dash
|
||||
('zulip://bot-name@apprise/{}'.format('a' * 32), {
|
||||
'instance': plugins.NotifyZulip,
|
||||
'privacy_url': 'zulip://bot-name@apprise/a...a/',
|
||||
}),
|
||||
# Valid everything - no target so default is used
|
||||
('zulip://botname@apprise/{}'.format('a' * 32), {
|
||||
'instance': plugins.NotifyZulip,
|
||||
|
Loading…
Reference in New Issue
Block a user