diff --git a/libraries/Microsoft.Bot.Builder.LanguageGeneration/Evaluator.cs b/libraries/Microsoft.Bot.Builder.LanguageGeneration/Evaluator.cs index 9eb3c6daca..aea1460327 100644 --- a/libraries/Microsoft.Bot.Builder.LanguageGeneration/Evaluator.cs +++ b/libraries/Microsoft.Bot.Builder.LanguageGeneration/Evaluator.cs @@ -593,11 +593,14 @@ private EvaluatorLookup CustomizedEvaluatorLookup(EvaluatorLookup baseLookup) return new ExpressionEvaluator(template, FunctionUtils.Apply(this.TemplateFunction()), ReturnType.Object, this.ValidateTemplateFunction); } - const string fromFile = "fromFile"; - - if (name.Equals(fromFile, StringComparison.Ordinal)) + if (LanguageGeneration.Templates.EnableFromFile) { - return new ExpressionEvaluator(fromFile, FunctionUtils.Apply(FromFile()), ReturnType.String, ValidateFromFile); + const string fromFile = "fromFile"; + + if (name.Equals(fromFile, StringComparison.Ordinal)) + { + return new ExpressionEvaluator(fromFile, FunctionUtils.Apply(FromFile()), ReturnType.String, ValidateFromFile); + } } const string activityAttachment = "ActivityAttachment"; diff --git a/libraries/Microsoft.Bot.Builder.LanguageGeneration/Expander.cs b/libraries/Microsoft.Bot.Builder.LanguageGeneration/Expander.cs index b5c0235d13..9de935d076 100644 --- a/libraries/Microsoft.Bot.Builder.LanguageGeneration/Expander.cs +++ b/libraries/Microsoft.Bot.Builder.LanguageGeneration/Expander.cs @@ -533,11 +533,14 @@ private EvaluatorLookup CustomizedEvaluatorLookup(EvaluatorLookup baseLookup, bo return new ExpressionEvaluator(template, FunctionUtils.Apply(this.TemplateFunction()), ReturnType.Object, this.ValidateTemplateFunction); } - const string fromFile = "fromFile"; - - if (name.Equals(fromFile, StringComparison.Ordinal)) + if (LanguageGeneration.Templates.EnableFromFile) { - return new ExpressionEvaluator(fromFile, FunctionUtils.Apply(this.FromFile()), ReturnType.String, ValidateFromFile); + const string fromFile = "fromFile"; + + if (name.Equals(fromFile, StringComparison.Ordinal)) + { + return new ExpressionEvaluator(fromFile, FunctionUtils.Apply(this.FromFile()), ReturnType.String, ValidateFromFile); + } } const string activityAttachment = "ActivityAttachment"; diff --git a/libraries/Microsoft.Bot.Builder.LanguageGeneration/Templates.cs b/libraries/Microsoft.Bot.Builder.LanguageGeneration/Templates.cs index 4aac3ee16a..726b094c66 100644 --- a/libraries/Microsoft.Bot.Builder.LanguageGeneration/Templates.cs +++ b/libraries/Microsoft.Bot.Builder.LanguageGeneration/Templates.cs @@ -74,6 +74,14 @@ public Templates( InjectToExpressionFunction(); } + /// + /// Gets or sets a value indicating whether fromFile is allowed in LG templates. + /// + /// + /// Boolean where true indicates fromFile is allowed. + /// + public static bool EnableFromFile { get; set; } = true; + /// /// Gets get all templates from current lg file and reference lg files. /// diff --git a/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/TemplatesTest.cs b/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/TemplatesTest.cs index 538ada69e9..adb07f64c4 100644 --- a/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/TemplatesTest.cs +++ b/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/TemplatesTest.cs @@ -1743,6 +1743,18 @@ public void TestFileOperation() Assert.Equal("hi ${name}", evaluated); } + [Fact] + public void TestFileOperationDisabled() + { + Templates.EnableFromFile = false; + + Assert.Throws(() => + { + var templates = Templates.ParseFile(GetExampleFilePath("FileOperation.lg")); + var evaluated = templates.Evaluate("FromFileWithoutEvaluation"); + }); + } + public class LoopClass { public string Name { get; set; }