mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-14 01:02:59 -07:00
Replace eval functions with helpers to catch exceptions
This commit is contained in:
parent
3510224cde
commit
a2b2d1d227
2 changed files with 18 additions and 4 deletions
|
@ -530,6 +530,20 @@ def cast_to_float(s):
|
|||
return 0
|
||||
|
||||
|
||||
def helper_divmod(a, b):
|
||||
try:
|
||||
return divmod(a, b)
|
||||
except (ValueError, TypeError):
|
||||
return 0
|
||||
|
||||
|
||||
def helper_round(n, ndigits):
|
||||
try:
|
||||
return round(n, ndigits)
|
||||
except (ValueError, TypeError):
|
||||
return 0
|
||||
|
||||
|
||||
def convert_xml_to_json(xml):
|
||||
o = xmltodict.parse(xml)
|
||||
return json.dumps(o)
|
||||
|
|
|
@ -1818,10 +1818,10 @@ def str_eval(field_name, kwargs):
|
|||
field_name = field_name.strip('`')
|
||||
allowed_names = {
|
||||
'bool': bool,
|
||||
'divmod': divmod,
|
||||
'float': float,
|
||||
'int': int,
|
||||
'round': round,
|
||||
'divmod': helpers.helper_divmod,
|
||||
'float': helpers.cast_to_float,
|
||||
'int': helpers.cast_to_int,
|
||||
'round': helpers.helper_round,
|
||||
'str': str
|
||||
}
|
||||
allowed_names.update(kwargs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue