mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-19 04:49:36 -07:00
Replace colon and exclamation in notification eval expression
This commit is contained in:
parent
05a00e9872
commit
670d2b31f7
1 changed files with 19 additions and 7 deletions
|
@ -1840,6 +1840,11 @@ def str_eval(field_name, kwargs):
|
||||||
class CustomFormatter(Formatter):
|
class CustomFormatter(Formatter):
|
||||||
def __init__(self, default='{{{0}}}'):
|
def __init__(self, default='{{{0}}}'):
|
||||||
self.default = default
|
self.default = default
|
||||||
|
self.eval_regex = re.compile(r'`.*?`')
|
||||||
|
self.eval_replace = {
|
||||||
|
':': '%%colon%%',
|
||||||
|
'!': '%%exclamation%%'
|
||||||
|
}
|
||||||
|
|
||||||
def convert_field(self, value, conversion):
|
def convert_field(self, value, conversion):
|
||||||
if conversion is None:
|
if conversion is None:
|
||||||
|
@ -1887,13 +1892,20 @@ class CustomFormatter(Formatter):
|
||||||
return super(CustomFormatter, self).get_value(key, args, kwargs)
|
return super(CustomFormatter, self).get_value(key, args, kwargs)
|
||||||
|
|
||||||
def parse(self, format_string):
|
def parse(self, format_string):
|
||||||
|
# Replace characters in eval expression
|
||||||
|
for match in re.findall(self.eval_regex, format_string):
|
||||||
|
replaced = match
|
||||||
|
for k, v in self.eval_replace.items():
|
||||||
|
replaced = replaced.replace(k, v)
|
||||||
|
format_string = format_string.replace(match, replaced)
|
||||||
|
|
||||||
parsed = super(CustomFormatter, self).parse(format_string)
|
parsed = super(CustomFormatter, self).parse(format_string)
|
||||||
|
|
||||||
for literal_text, field_name, format_spec, conversion in parsed:
|
for literal_text, field_name, format_spec, conversion in parsed:
|
||||||
# Fix colon (:) inside an eval expression being parsed as a format specifier
|
# Restore characters in eval expression
|
||||||
if (field_name and field_name.startswith('`') and
|
if field_name:
|
||||||
format_spec and format_spec.endswith('`')):
|
for k, v in self.eval_replace.items():
|
||||||
field_name += ':' + format_spec
|
field_name = field_name.replace(v, k)
|
||||||
format_spec = ''
|
|
||||||
|
|
||||||
real_format_string = ''
|
real_format_string = ''
|
||||||
if field_name:
|
if field_name:
|
||||||
|
@ -1906,8 +1918,8 @@ class CustomFormatter(Formatter):
|
||||||
prefix = None
|
prefix = None
|
||||||
suffix = None
|
suffix = None
|
||||||
|
|
||||||
matches = re.findall(r'`.*?`', real_format_string)
|
matches = re.findall(self.eval_regex, real_format_string)
|
||||||
temp_format_string = re.sub(r'`.*`', '{}', real_format_string)
|
temp_format_string = re.sub(self.eval_regex, '{}', real_format_string)
|
||||||
|
|
||||||
prefix_split = temp_format_string.split('<')
|
prefix_split = temp_format_string.split('<')
|
||||||
if len(prefix_split) == 2:
|
if len(prefix_split) == 2:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue