We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents bb96cbb + 3430bab commit 329433cCopy full SHA for 329433c
1 file changed
quantities/registry.py
@@ -1,8 +1,8 @@
1
"""
2
3
4
-import copy
5
import re
+import builtins
6
7
8
class UnitRegistry:
@@ -16,6 +16,17 @@ def __init__(self):
16
self.__context = {}
17
18
def __getitem__(self, string):
19
+
20
+ # easy hack to prevent arbitrary evaluation of code
21
+ all_builtins = dir(builtins)
22
+ # because we have kilobytes, other bytes we have to remove bytes
23
+ all_builtins.remove("bytes")
24
+ # have to deal with octet as well
25
+ all_builtins.remove("oct")
26
+ for builtin in all_builtins:
27
+ if builtin in string:
28
+ raise RuntimeError(f"String parsing error for {string}. Enter a string accepted by quantities")
29
30
try:
31
return eval(string, self.__context)
32
except NameError:
0 commit comments