Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apparun/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def validate_expr(expr: str) -> bool:
"L_PAREN": ["OP", "ID", "L_PAREN", "COMMA", "FUN_ID"],
"R_PAREN": ["NUMBER", "ID", "R_PAREN"],
"COMMA": ["NUMBER", "ID", "R_PAREN"],
"OP": ["NUMBER", "ID", "R_PAREN"],
"OP": ["NUMBER", "ID", "L_PAREN", "R_PAREN"],
}

expr_copy = str(expr)
Expand Down Expand Up @@ -94,7 +94,7 @@ def validate_expr(expr: str) -> bool:
valid = False

fun_names = re.findall(tokens_patterns["FUN_ID"], expr)
allowed_funcs = dir(math) + dir(numpy)
allowed_funcs = dir(math) + dir(numpy.core) + dir(sympy.functions)
return valid and nb_paren == 0 and all(fun in allowed_funcs for fun in fun_names)


Expand Down
3 changes: 3 additions & 0 deletions tests/functional/test_arithmetic_expression_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def test_valid_exprs():
"3*a_",
"3*a_1",
"3*_a1",
"Abs(a)",
"abs(a)",
"1-exp(-defect_density*area)",
]

for expr in exprs:
Expand Down
Loading