Skip to content

Commit

Permalink
Merge pull request #4057 from microsoft/feich/fixStrictModeBug
Browse files Browse the repository at this point in the history
fix strict mode issue in expander
  • Loading branch information
Tom Laird-McConnell authored Jun 14, 2020
2 parents 2f0e402 + 18bc214 commit e899ee9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ private object EvalExpression(string exp, ParserRuleContext expressionContext =

CheckExpressionResult(exp, error, result, templateName, lineContent, errorPrefix);
}
else if (result == null && lgOptions.StrictMode != false)
else if (result == null && lgOptions.StrictMode != true)
{
result = "null";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ private List<string> EvalExpression(string exp, ParserRuleContext context = null

Evaluator.CheckExpressionResult(exp, error, result, templateName, lineContent, errorPrefix);
}
else if (result == null && lgOptions.StrictMode == false)
else if (result == null && lgOptions.StrictMode != true)
{
result = "null";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
> !# @strict = false

# StrictFalse
- ${variable_not_defined}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
> !# @strict = true

# StrictTrue
- ${variable_not_defined}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<None Remove="Examples\EvaluationOptions\d3.lg" />
<None Remove="Examples\EvaluationOptions\d4.lg" />
<None Remove="Examples\EvaluationOptions\f4.lg" />
<None Remove="Examples\EvaluationOptions\StrictModeTrue.lg" />
<None Remove="Examples\import\import3.lg" />
<None Remove="Examples\1.lg" />
<None Remove="Examples\2.lg" />
Expand All @@ -46,6 +47,7 @@
<None Remove="Examples\LGOptionTest.lg" />
<None Remove="Examples\MultilineTextForAdaptiveCard.lg" />
<None Remove="Examples\NonAdaptiveCardActivity.lg" />
<None Remove="Examples\StrictModeFalse.lg" />
<None Remove="Examples\switchcase.lg" />
<None Remove="Examples\TemplateNameWithDot.lg" />
<None Remove="Examples\TemplateRef.lg" />
Expand Down Expand Up @@ -161,6 +163,9 @@
<Content Include="Examples\EvaluationOptions\f4.lg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Examples\EvaluationOptions\StrictModeTrue.lg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Examples\ExpressionExtract.lg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand All @@ -170,6 +175,9 @@
<Content Include="Examples\EvaluationOptions\LGOptionTest.lg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Examples\EvaluationOptions\StrictModeFalse.lg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Examples\InjectionTest\common.lg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,20 @@ public void TestExpandTemplateWithEmptyListInStructuredLG()
Assert.AreEqual(JObject.Parse(evaled[0].ToString())["inputhint"].ToString(), "ignoringInput");
}

[TestMethod]
public void TestExpandTemplateWithStrictMode()
{
var templates = Templates.ParseFile(GetExampleFilePath("EvaluationOptions/StrictModeFalse.lg"));

var evaled = templates.ExpandTemplate("StrictFalse");
Assert.AreEqual("null", evaled[0].ToString());

templates = Templates.ParseFile(GetExampleFilePath("EvaluationOptions/StrictModeTrue.lg"));

var exception = Assert.ThrowsException<Exception>(() => templates.ExpandTemplate("StrictTrue"));
Assert.IsTrue(exception.Message.Contains("'variable_not_defined' evaluated to null. [StrictTrue] Error occurred when evaluating '-${variable_not_defined}'"));
}

[TestMethod]
public void TestEvalExpression()
{
Expand Down

0 comments on commit e899ee9

Please sign in to comment.