I have an AWS lambda function that receives user's code from a browser as a string and runs eval
in a sandboxed environment as in a standard REPL. I am not trying to interpolate a string. I am trying to have eval
recognize and perform operations on strings.
I am somewhat limited in the operations I can perform. Basic regex replacement is cool, but I don't think I would be able to do anything more involved than that, but perhaps I'm mistaken.
This works for basic arithmetic operations, the creation of class instances, etc. However, it fails to perform string operations properly. When I pass:
eval `("3*4")`
it returns 12
, which is great. However, if I pass:
eval(""str:" + " test"")
it fails to return "str: test"
. In fact it returns nothing.
It has been suggested that I escape the double quotes. In a REPL, replacing all double quotes with escaped ones, such as \"
, works.
eval("\"str \" + \"test\"") # => "str test"
However, when I try this with AWS, it returns "\"str \" + \"test\""
.
I look forward to hearing your responses.