Skip to content

Commit

Permalink
Merge pull request #462 from 27rabbitlt/fix_dotj_forbidden_ctrl_char
Browse files Browse the repository at this point in the history
fix sanitizer forbid usage of \d+.\d*j
  • Loading branch information
FrancescAlted authored Dec 4, 2023
2 parents 05bb401 + bf9d34a commit 88ba205
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion numexpr/necompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def __str__(self):

_flow_pat = r'[\;\[\:]'
_dunder_pat = r'(^|[^\w])__[\w]+__($|[^\w])'
_attr_pat = r'\.\b(?!(real|imag|\d*[eE]?[+-]?\d+)\b)'
_attr_pat = r'\.\b(?!(real|imag|(\d*[eE]?[+-]?\d+)|\d*j)\b)'
_blacklist_re = re.compile(f'{_flow_pat}|{_dunder_pat}|{_attr_pat}')

def stringToExpression(s, types, context, sanitize: bool=True):
Expand All @@ -275,6 +275,7 @@ def stringToExpression(s, types, context, sanitize: bool=True):
# parse into its homebrew AST. This is to protect the call to `eval` below.
# We forbid `;`, `:`. `[` and `__`, and attribute access via '.'.
# We cannot ban `.real` or `.imag` however...
# We also cannot ban `.\d*j`, where `\d*` is some digits (or none), e.g. 1.5j, 1.j
if sanitize:
no_whitespace = re.sub(r'\s+', '', s)
if _blacklist_re.search(no_whitespace) is not None:
Expand Down

0 comments on commit 88ba205

Please sign in to comment.