Skip to content

Commit bb377ee

Browse files
committed
fix: added missing parameters for safeEval
1 parent f0b9ef7 commit bb377ee

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
This file documents any relevant changes.
44

5+
## [1.0.8] - 2021-11-10
6+
- Fix: EvalFormatStrings now work properly again
7+
58
## [1.0.7] - 2021-09-30
69
- Fix: interalEdit Forms no longer lose data
710

flare/forms/formatString.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def formatString(format: str, data: typing.Dict, structure=None, language=None):
1212
1313
"""
1414
if "$(" in format:
15-
return formatStringHandler(format,data,structure,language=language)
15+
return formatStringHandler(format, data, structure, language=language)
16+
return evalStringHandler(format, data, structure, language)
1617

17-
return evalStringHandler(format,data,structure,language)
1818

1919
# formatString ---------------------------------------------------------------------------------------------------------
2020
def formatOneEntry(key, format, data, structure=None, prefix=None, language=None, context=None, _rec=0):
@@ -43,7 +43,8 @@ def formatOneEntry(key, format, data, structure=None, prefix=None, language=None
4343
res, val, structure, prefix + [key], language, _rec=_rec + 1
4444
)
4545

46-
elif isinstance(val, list) and len(val) > 0 and isinstance(val[0], dict): # if bone is relationalbone with rel and dest
46+
elif isinstance(val, list) and len(val) > 0 and isinstance(val[0],
47+
dict): # if bone is relationalbone with rel and dest
4748
if struct and "dest" in val[0] and "rel" in val[0]:
4849
if "relskel" in struct and "format" in struct:
4950
format = struct["format"]
@@ -83,6 +84,7 @@ def formatOneEntry(key, format, data, structure=None, prefix=None, language=None
8384
res = res.replace("$(%s)" % (".".join(prefix + [key])), str(val))
8485
return res
8586

87+
8688
def formatStringHandler(format, data, structure=None, prefix=None, language=None, context=None, _rec=0):
8789
"""Parses a string given by format and substitutes placeholders using values specified by data.
8890
The syntax for the placeholders is $(%s).
@@ -104,7 +106,7 @@ def formatStringHandler(format, data, structure=None, prefix=None, language=None
104106
:return: The traversed string with the replaced values.
105107
:rtype: str
106108
"""
107-
#print("FORMAT STRING", format, data, structure, prefix)
109+
# print("FORMAT STRING", format, data, structure, prefix)
108110
if structure and isinstance(structure, list):
109111
structure = {k: v for k, v in structure}
110112

@@ -130,8 +132,10 @@ def formatStringHandler(format, data, structure=None, prefix=None, language=None
130132

131133
return res
132134

135+
133136
# displayString ---------------------------------------------------------------------------------------------------------
134-
def displayStringHandler(display: str, value: typing.Dict, structure: typing.Dict, language: str = "de") -> [html5.Widget]:
137+
def displayStringHandler(display: str, value: typing.Dict, structure: typing.Dict, language: str = "de") -> [
138+
html5.Widget]:
135139
from flare.forms import boneSelector
136140

137141
# --- Helpers ---
@@ -142,6 +146,7 @@ def listToDict(l):
142146

143147
assert isinstance(l, dict)
144148
return l
149+
145150
# ---------------
146151

147152
widgets = []
@@ -188,17 +193,20 @@ def listToDict(l):
188193

189194
return widgets
190195

196+
191197
# evalString ---------------------------------------------------------------------------------------------------------
192198
def evalStringHandler(format, data, structure, language):
193199
if not html5.core.htmlExpressionEvaluator:
194200
return format
195201

196202
try:
197-
value = html5.core.htmlExpressionEvaluator.execute(format, data)
203+
value = html5.core.htmlExpressionEvaluator.execute(format, {"value":data,
204+
"structure":structure,
205+
"language":language
206+
}
207+
)
198208
except Exception as e:
199209
logging.exception(e)
200210
value = "(invalid format string)"
201211

202212
return value
203-
204-

0 commit comments

Comments
 (0)