diff --git a/SafeExamBrowser.Browser.UnitTests/Filters/Rules/SimplifiedRuleTests.cs b/SafeExamBrowser.Browser.UnitTests/Filters/Rules/SimplifiedRuleTests.cs index e1c43dea..3a47b0d8 100644 --- a/SafeExamBrowser.Browser.UnitTests/Filters/Rules/SimplifiedRuleTests.cs +++ b/SafeExamBrowser.Browser.UnitTests/Filters/Rules/SimplifiedRuleTests.cs @@ -80,24 +80,26 @@ namespace SafeExamBrowser.Browser.UnitTests.Filters.Rules [TestMethod] public void TestAlphanumericExpression() { - var expression = "hostname-123"; + var expression = "hostname123"; var positive = new[] { - $"scheme://{expression}", - // TODO: All these below should not be allowed! + $"scheme://{expression}" + }; + var negative = new[] + { + $"scheme://hostname", + $"scheme://hostname1", + $"scheme://hostname12", + $"scheme://hostname1234", $"scheme://{expression}.org", $"scheme://www.{expression}.org", $"scheme://subdomain.{expression}.com", $"scheme://www.realhost.{expression}", $"scheme://subdomain-1.subdomain-2.{expression}.org", - $"scheme://user:password@www.{expression}.org/path/file.txt?param=123#fragment" - }; - var negative = new[] - { - $"scheme://hostname", + $"scheme://user:password@www.{expression}.org/path/file.txt?param=123#fragment", $"scheme://{expression}4", $"scheme://hostname.org", - $"scheme://hostname-12.org", + $"scheme://hostname12.org", $"scheme://{expression}4.org", $"scheme://{expression}.realhost.org", $"scheme://subdomain.{expression}.realhost.org", @@ -892,7 +894,7 @@ namespace SafeExamBrowser.Browser.UnitTests.Filters.Rules Test(expression, positive, negative); } - private void Test(string expression, string[] positive, string[] negative, bool testLegacy = true) // TODO: Remove flag once issues cleared! + private void Test(string expression, string[] positive, string[] negative, bool testLegacy = true) { var legacy = new LegacyFilter(expression); diff --git a/SafeExamBrowser.Browser/Filters/Rules/SimplifiedRule.cs b/SafeExamBrowser.Browser/Filters/Rules/SimplifiedRule.cs index fe5cbb2d..065d1349 100644 --- a/SafeExamBrowser.Browser/Filters/Rules/SimplifiedRule.cs +++ b/SafeExamBrowser.Browser/Filters/Rules/SimplifiedRule.cs @@ -93,20 +93,14 @@ namespace SafeExamBrowser.Browser.Filters.Rules private void ParseHost(string expression) { - var hasToplevelDomain = Regex.IsMatch(expression, @"\.+"); - var hasSubdomain = Regex.IsMatch(expression, @"\.{2,}"); + var isAlphanumeric = Regex.IsMatch(expression, @"^[a-zA-Z0-9]+$"); var matchExactSubdomain = expression.StartsWith("."); expression = matchExactSubdomain ? expression.Substring(1) : expression; expression = Regex.Escape(expression); expression = ReplaceWildcard(expression); - if (!hasToplevelDomain) - { - expression = $@"{expression}(\.[a-z]+)?"; - } - - if (!hasSubdomain && !matchExactSubdomain) + if (!isAlphanumeric && !matchExactSubdomain) { expression = $@"(.+?\.)*{expression}"; }