Fixed an issue with ast literal eval parsing 7e7 as a mathematical operation instead of pure string

This commit is contained in:
frikky
2022-04-21 19:00:50 +02:00
parent 240a03a9a5
commit bcf2119a7c
+4 -3
View File
@@ -3089,11 +3089,12 @@ class AppBase:
for key, value in params.items(): for key, value in params.items():
try: try:
if isinstance(value, str) and ((value.startswith("{") and value.endswith("}")) or (value.startswith("[") and value.endswith("]"))): if isinstance(value, str) and ((value.startswith("{") and value.endswith("}")) or (value.startswith("[") and value.endswith("]"))):
params[key] = ast.literal_eval(value) params[key] = json.loads(value)
except Exception as e: except Exception as e:
try: try:
params[key] = json.loads(value) if isinstance(value, str) and ((value.startswith("{") and value.endswith("}")) or (value.startswith("[") and value.endswith("]"))):
except json.decoder.JSONDecodeError as e: params[key] = ast.literal_eval(value)
except Exception as e:
self.logger.info(f"[DEBUG] Failed parsing value with ast and json.loads - noncritical. Trying next: {e}") self.logger.info(f"[DEBUG] Failed parsing value with ast and json.loads - noncritical. Trying next: {e}")
continue continue
except Exception as e: except Exception as e: