Skip to content

Commit ce637be

Browse files
committed
fix: addition of null and bubble container
1 parent 0685013 commit ce637be

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Newtonsoft.Json;
1+
using Microsoft.CSharp.RuntimeBinder;
2+
using Newtonsoft.Json;
23
using NUnit.Framework;
34
using Shouldly;
45
using System;
@@ -1837,6 +1838,15 @@ public void Evaluate_DoubleDoubleQuotesInEscapedStringThrowException()
18371838

18381839
evaluator.Evaluate("@\"Hello \"\" Joe\"").ShouldBe(@"Hello "" Joe");
18391840
}
1841+
1842+
[Test]
1843+
[Category("Bug")]
1844+
public void Evaluate_NullAdditionShouldThrowExceptionNotReturnString()
1845+
{
1846+
var evaluator = new ExpressionEvaluator();
1847+
1848+
Should.Throw<RuntimeBinderException>(() => evaluator.Evaluate("(null + null) + null"));
1849+
}
18401850

18411851
//[Test]
18421852
//[Category("Bug")]

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,11 +3296,11 @@ void EvaluateFirstPreviousUnaryOp(int j)
32963296
{
32973297
list[i] = operatorEvalutationsDict[eOp](left, right);
32983298

3299-
if (left is BubbleExceptionContainer && right is string)
3299+
if (left is BubbleExceptionContainer && right is string or null)
33003300
{
33013301
list[i] = left; //Bubble up the causing error
33023302
}
3303-
else if (right is BubbleExceptionContainer && left is string)
3303+
else if (right is BubbleExceptionContainer && left is string or null)
33043304
{
33053305
list[i] = right; //Bubble up the causing error
33063306
}

0 commit comments

Comments
 (0)