mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-14 02:26:58 -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):
|
||||
def __init__(self, default='{{{0}}}'):
|
||||
self.default = default
|
||||
self.eval_regex = re.compile(r'`.*?`')
|
||||
self.eval_replace = {
|
||||
':': '%%colon%%',
|
||||
'!': '%%exclamation%%'
|
||||
}
|
||||
|
||||
def convert_field(self, value, conversion):
|
||||
if conversion is None:
|
||||
|
@ -1887,13 +1892,20 @@ class CustomFormatter(Formatter):
|
|||
return super(CustomFormatter, self).get_value(key, args, kwargs)
|
||||
|
||||
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)
|
||||
|
||||
for literal_text, field_name, format_spec, conversion in parsed:
|
||||
# Fix colon (:) inside an eval expression being parsed as a format specifier
|
||||
if (field_name and field_name.startswith('`') and
|
||||
format_spec and format_spec.endswith('`')):
|
||||
field_name += ':' + format_spec
|
||||
format_spec = ''
|
||||
# Restore characters in eval expression
|
||||
if field_name:
|
||||
for k, v in self.eval_replace.items():
|
||||
field_name = field_name.replace(v, k)
|
||||
|
||||
real_format_string = ''
|
||||
if field_name:
|
||||
|
@ -1906,8 +1918,8 @@ class CustomFormatter(Formatter):
|
|||
prefix = None
|
||||
suffix = None
|
||||
|
||||
matches = re.findall(r'`.*?`', real_format_string)
|
||||
temp_format_string = re.sub(r'`.*`', '{}', real_format_string)
|
||||
matches = re.findall(self.eval_regex, real_format_string)
|
||||
temp_format_string = re.sub(self.eval_regex, '{}', real_format_string)
|
||||
|
||||
prefix_split = temp_format_string.split('<')
|
||||
if len(prefix_split) == 2:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue