mparlak / Flee

Fast Lightweight Expression Evaluator
630 stars 121 forks source link

Unexpected token in string if there is a \ in a string #66

Closed calico-crusade closed 3 years ago

calico-crusade commented 5 years ago

I created a unit test to show the issue;

        [TestMethod]
        public void TestEnvironmentExpression()
        {
            var clause = @"""\\fileserver_"" + Env + ""\"" + Env + ""_applications\"" + FileName";
            var flee = new ExpressionContext();
            flee.Variables.Add("Env", "dev");
            flee.Variables.Add("FileName", "something.txt");

            var result = flee.CompileDynamic(clause).Evaluate();
        }

The exception that appears; "SyntaxError: unexpected token \"_applications\" , expected , on line: 1 column: 38"

Full stack trace (with sensitive info **'d out:

Flee.PublicTypes.ExpressionCompileException: SyntaxError: unexpected token "_applications" <IDENTIFIER>, expected <EOF>, on line: 1 column: 38 
---> Flee.Parsing.grammatica_1._5.alpha2.PerCederberg.Grammatica.Runtime.ParserLogException: unexpected token "_applications" <IDENTIFIER>, expected <EOF>, on line: 1 column: 38
   at Flee.Parsing.grammatica_1._5.alpha2.PerCederberg.Grammatica.Runtime.Parser.Parse()
   at Flee.PublicTypes.ExpressionContext.DoParse()
   --- End of inner exception stack trace ---
   at Flee.PublicTypes.ExpressionContext.DoParse()
   at Flee.PublicTypes.ExpressionContext.Parse(String expression, IServiceProvider services)
   at Flee.InternalTypes.Expression`1.Compile(String expression, ExpressionOptions options)
   at Flee.InternalTypes.Expression`1..ctor(String expression, ExpressionContext context, Boolean isGeneric)
   at Flee.PublicTypes.ExpressionContext.CompileDynamic(String expression)
   at ***() in C:\***Tests.cs:line 89}  Flee.PublicTypes.ExpressionCompileException
NetDefender commented 3 years ago

There are some missing '\' in the formula. The following formula works:

var clause = @"""\\\\fileserver_"" + Env + ""\\"" + Env + ""_applications\\"" + FileName";

dotnetfiddle

calico-crusade commented 3 years ago

I'm closing this; I don't even remember what project this was for, but I don't think we're using flee anymore, anyway.