TomFrost / Jexl

Javascript Expression Language: Powerful context-based expression parser and evaluator
MIT License
559 stars 90 forks source link

Updated escEscRegex to handle backslash globally #131

Closed cosmos-lab closed 1 year ago

cosmos-lab commented 1 year ago

Please check the sequence:

let exp = "\"c:\\foo\\bar\"";

let ast = jexl.compile(exp)._getAst();
console.log(ast) //{"type": "Literal", "value": "c:\\foo\\bar"}

exp = jexlExpressionStringFromAst(jexl._grammar, ast) 
console.log(exp) //"c:\\foo\\bar"

ast = jexl.compile(exp)._getAst();
console.log(ast) //{"type": "Literal", "value": "c:\\foo\\\\bar"}

exp = jexlExpressionStringFromAst(jexl._grammar, ast) 
console.log(exp) //"c:\\foo\\\\bar"

If we check only first backslash is getting unescaped.

Fix: Make var escEscRegex = /\/; to var escEscRegex = /\/g; In Lexer.js