fix(safe_eval): Normalize code passed before validating the code

This commit is contained in:
Suraj Shetty 2023-06-04 08:59:08 +05:30
parent 4a81d9f8e3
commit 65a2cdcffc

View file

@ -16,6 +16,7 @@ import inspect
import json
import os
import re
import unicodedata
import warnings
from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, TypeAlias, overload
@ -2271,6 +2272,7 @@ def bold(text):
def safe_eval(code, eval_globals=None, eval_locals=None):
"""A safer `eval`"""
whitelisted_globals = {"int": int, "float": float, "long": int, "round": round}
code = unicodedata.normalize("NFKC", code)
UNSAFE_ATTRIBUTES = {
# Generator Attributes