nreco / lambdaparser

Runtime parser for string expressions (formulas, method calls). Builds dynamic LINQ expression tree and compiles it to lambda delegate.
http://www.nrecosite.com/
MIT License
307 stars 55 forks source link

escaping quotes in nested strings #23

Closed lerljaku closed 4 years ago

lerljaku commented 4 years ago

parsing fails with string in expression

test string:

var exp = "true ? \"<br><br><span style=\\\"color:red;\\\">hello</span> world\" : \"\""

var result = SUT.Eval(exp, new Dictionary<string, object>());

fails with

NReco.Linq.LambdaParserException : Expected ':' at 30: true ? "<br><br><span style=\"color:red;\">hello</span> world" : ""
   at NReco.Linq.LambdaParser.ParseConditional(String expr, Int32 start)
   at NReco.Linq.LambdaParser.Parse(String expr)
   at NReco.Linq.LambdaParser.Eval(String expr, Func`2 getVarValue)
   at NReco.Linq.LambdaParser.Eval(String expr, IDictionary`2 vars)
VitaliyMF commented 4 years ago

\" is not a valid escape sequence for LambdaParser, only way to include " is "" (sequence of 2 double quotes that are treated as ").

If you want to support \" you can simply do exp.Replace("\\\"", "\"\"")

lerljaku commented 4 years ago

ty!, its all cool for me :] (sorry if i missed it in documentation somewhere)