diff --git a/Terminal.Gui/FileServices/AllowedType.cs b/Terminal.Gui/FileServices/AllowedType.cs index 36b1823a0..f5a81f052 100644 --- a/Terminal.Gui/FileServices/AllowedType.cs +++ b/Terminal.Gui/FileServices/AllowedType.cs @@ -94,14 +94,22 @@ namespace Terminal.Gui { /// public bool IsAllowed(string path) { + if(string.IsNullOrWhiteSpace(path)) { + return false; + } + var extension = Path.GetExtension (path); + if(this.Extensions.Any(e=>path.EndsWith(e, StringComparison.InvariantCultureIgnoreCase))) { + return true; + } + // There is a requirement to have a particular extension and we have none if (string.IsNullOrEmpty (extension)) { return false; } - return this.Extensions.Any (e => e.Equals (extension)); + return this.Extensions.Any (e => e.Equals (extension, StringComparison.InvariantCultureIgnoreCase)); } } diff --git a/UnitTests/FileServices/FileDialogTests.cs b/UnitTests/FileServices/FileDialogTests.cs index 5d5b92551..5d1b1f282 100644 --- a/UnitTests/FileServices/FileDialogTests.cs +++ b/UnitTests/FileServices/FileDialogTests.cs @@ -481,6 +481,37 @@ namespace Terminal.Gui.FileServicesTests { }; } + [Theory] + [InlineData (".csv", null, false)] + [InlineData (".csv", "", false)] + [InlineData (".csv", "c:\\MyFile.csv", true)] + [InlineData (".csv", "c:\\MyFile.CSV", true)] + [InlineData (".csv", "c:\\MyFile.csv.bak", false)] + public void TestAllowedType_Basic(string allowed, string candidate, bool expected) + { + Assert.Equal (expected, new AllowedType ("Test", allowed).IsAllowed (candidate)); + } + + [Theory] + [InlineData ("Dockerfile", "c:\\temp\\Dockerfile", true)] + [InlineData ("Dockerfile", "Dockerfile", true)] + [InlineData ("Dockerfile", "someimg.Dockerfile", true)] + public void TestAllowedType_SpecificFile(string allowed, string candidate, bool expected) + { + Assert.Equal (expected, new AllowedType ("Test", allowed).IsAllowed (candidate)); + } + + [Theory] + [InlineData (".Designer.cs", "c:\\MyView.Designer.cs", true)] + [InlineData (".Designer.cs", "c:\\temp/MyView.Designer.cs", true)] + [InlineData(".Designer.cs","MyView.Designer.cs",true)] + [InlineData (".Designer.cs", "c:\\MyView.DESIGNER.CS", true)] + [InlineData (".Designer.cs", "MyView.cs", false)] + public void TestAllowedType_DoubleBarreled (string allowed, string candidate, bool expected) + { + Assert.Equal (expected, new AllowedType ("Test", allowed).IsAllowed (candidate)); + } + [Theory, AutoInitShutdown] [InlineData (true)] [InlineData (false)]