You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LiteDB 5.0.1 and the latest from repo, Windows 10, net45
Describe the bug
In the expression X AND Y, Y is evaluated even if X is evaluated to false.
As a result, evaluation of Y may fail when X is supposed to avoid evaluation of Y with invalid arguments.
Code to Reproduce
varex1=BsonExpression.Create("LENGTH($.x) >= 5 AND SUBSTRING($.x, 0, 5) = \"12345\"");vardoc1=newBsonDocument();// OK (true)doc1["x"]="12345";varr1=ex1.ExecuteScalar(doc1);Console.WriteLine($"{r1}");// KO (expected: false, actual: exception)doc1["x"]="123";varr2=ex1.ExecuteScalar(doc1);Console.WriteLine($"{r2}");
Expected behavior
See code comments.
Screenshots/Stacktrace
Output of the above code:
true
Unhandled Exception: System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length
at System.String.Substring(Int32 startIndex, Int32 length)
at LiteDB.BsonExpressionMethods.SUBSTRING(BsonValue value, BsonValue startIndex, BsonValue length)
at lambda_method(Closure , IEnumerable`1 , BsonDocument , BsonValue , Collation , BsonDocument )
at LiteDB.BsonExpression.ExecuteScalar(IEnumerable`1 source, BsonDocument root, BsonValue current, Collation collation)
at LiteDB.BsonExpression.ExecuteScalar(BsonDocument root, Collation collation)
The text was updated successfully, but these errors were encountered:
Hi @nightroman, thanks again for discover this. I change expression implementation to use AndAlso and OrElse in BsonExpression parser and compiler. Will be avaiable in next version.
Version
LiteDB 5.0.1 and the latest from repo, Windows 10, net45
Describe the bug
In the expression
X AND Y
,Y
is evaluated even ifX
is evaluated tofalse
.As a result, evaluation of
Y
may fail whenX
is supposed to avoid evaluation ofY
with invalid arguments.Code to Reproduce
Expected behavior
See code comments.
Screenshots/Stacktrace
Output of the above code:
The text was updated successfully, but these errors were encountered: