I have a script which takes user input, performs some operations on that input and then executes the modified input.
Example:
User enters ‘vbscipt or javascript’
My script converts it to:
var searchtest = "mystring.search('vbscript')>=0 || mystring.search('javascript')>=0";
And executes it using eval(searchtest);
However if the user enters ‘vbscript javascript’
My script converts it to
var searchtest = "mystring.search('vbscript')>=0 mystring.search('javascript')>=0";
(Note lack of ||) Which will cause an error when I call eval(searchtest);
Is there a way to test the searchtest string to determine if it is a valid javascript expression before executing it?
JavaScript eval is evil !!
Instead of transforming user input as you are doing why not something like the following :
I am assuming your expresson can be a sequence of
ands andors withands taking precedence