I have to deal with a customers Javascript Framework for a very specific task.
I have this html:
<div data-foo="(#a = #b)">...loading</div>
In Javascript I get the data-*-Attribute as a string:
foo = '(#a = #b)'
then an ajax call is made with the following answer:
#a=1, #b=1
next the tags are replaced with the values from ajax call (and the operator is replaced as well):
foo = '(1 == 1)'
then foo is evaluated with eval();
result = eval(foo) // true
Is there a way to avoid eval()? I always have to evaluate string like '(0 == 1)' or '((0 == 0) && (1 == 0))'. I have no chance to influence servers resonse. I need a good and safe way to evaluate the strings to true or false.
EDIT:
possible strings are:
'(0 == 0)'
'(0 == 1)'
'(0 > 5)'
'(117 > 0)'
'((0 == 1) && (11 == 11))'
'((0 == 1) || (0 == 0))'
'(((0 < 1) || (0 == 0) ) && (33 != 11))'
...and so on!
the result always need to be true or false.