Skip to content

Commit 88ba205

Browse files
Merge pull request #462 from 27rabbitlt/fix_dotj_forbidden_ctrl_char
fix sanitizer forbid usage of \d+.\d*j
2 parents 05bb401 + bf9d34a commit 88ba205

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

numexpr/necompiler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def __str__(self):
265265

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

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

0 commit comments

Comments
 (0)