mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-05 06:50:29 +03:00
replace unneeded eval() call and support negative versionCodes
This commit is contained in:
parent
f0d27e1fa5
commit
4503e7a92a
2 changed files with 23 additions and 6 deletions
|
|
@ -3275,8 +3275,12 @@ def get_git_describe_link():
|
|||
|
||||
|
||||
def calculate_math_string(expr):
|
||||
ops = {ast.Add: operator.add, ast.Sub: operator.sub,
|
||||
ast.Mult: operator.mul}
|
||||
ops = {
|
||||
ast.Add: operator.add,
|
||||
ast.Mult: operator.mul,
|
||||
ast.Sub: operator.sub,
|
||||
ast.USub: operator.neg,
|
||||
}
|
||||
|
||||
def execute_ast(node):
|
||||
if isinstance(node, ast.Num): # <number>
|
||||
|
|
@ -3285,7 +3289,7 @@ def calculate_math_string(expr):
|
|||
return ops[type(node.op)](execute_ast(node.left),
|
||||
execute_ast(node.right))
|
||||
elif isinstance(node, ast.UnaryOp): # <operator> <operand> e.g., -1
|
||||
return ops[type(node.op)](eval(node.operand))
|
||||
return ops[type(node.op)](ast.literal_eval(node.operand))
|
||||
else:
|
||||
raise SyntaxError(node)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue