From fa9b84ba685408100f4f5f0576141c59744ac056 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Fri, 22 Nov 2019 15:28:05 +0100 Subject: [PATCH] SEBWIN-314: Fixed issues with legacy URL filter implementation. --- SebWindowsConfig/Utilities/SEBURLFilterExpression.cs | 8 ++++---- SebWindowsConfig/Utilities/SEBURLFilterRegexExpression.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SebWindowsConfig/Utilities/SEBURLFilterExpression.cs b/SebWindowsConfig/Utilities/SEBURLFilterExpression.cs index b3971748..f5e2b860 100644 --- a/SebWindowsConfig/Utilities/SEBURLFilterExpression.cs +++ b/SebWindowsConfig/Utilities/SEBURLFilterExpression.cs @@ -21,7 +21,7 @@ namespace SebWindowsConfig.Utilities if (!string.IsNullOrEmpty(filterExpressionString)) { /// Convert Uri to a SEBURLFilterExpression - string splitURLRegexPattern = @"(?:([^\:]*)\:\/\/)?(?:([^\:\@]*)(?:\:([^\@]*))?\@)?(?:([^\/‌​\:]*))?(?:\:([0-9\*]*))?([^\?#]*)?(?:\?([^#]*))?(?:#(.*))?"; + string splitURLRegexPattern = @"(?:([^\:]*)\:\/\/)?(?:([^\:\@]*)(?:\:([^\@]*))?\@)?(?:([^\/\:]*))?(?:\:([0-9\*]*))?([^\?#]*)?(?:\?([^#]*))?(?:#(.*))?"; Regex splitURLRegex = new Regex(splitURLRegexPattern); Match regexMatch = splitURLRegex.Match(filterExpressionString); if (regexMatch.Success == false) @@ -34,8 +34,8 @@ namespace SebWindowsConfig.Utilities this.password = regexMatch.Groups[3].Value; this.host = regexMatch.Groups[4].Value; - // Treat a special case when a query is interpreted as part of the host address - if (this.host.Contains("?")) + // Treat a special case when a query or fragment is interpreted as part of the host address + if (this.host.Contains("?") || this.host.Contains("#")) { string splitURLRegexPattern2 = @"([^\?#]*)?(?:\?([^#]*))?(?:#(.*))?"; Regex splitURLRegex2 = new Regex(splitURLRegexPattern2); @@ -64,7 +64,7 @@ namespace SebWindowsConfig.Utilities this.port = UInt16.Parse(portNumber); } - this.path = regexMatch.Groups[6].Value.Trim(new char[] { '/' }); + this.path = regexMatch.Groups[6].Value.TrimEnd(new char[] { '/' }); this.query = regexMatch.Groups[7].Value; this.fragment = regexMatch.Groups[8].Value; } diff --git a/SebWindowsConfig/Utilities/SEBURLFilterRegexExpression.cs b/SebWindowsConfig/Utilities/SEBURLFilterRegexExpression.cs index cd13ad8f..ba7abcb1 100644 --- a/SebWindowsConfig/Utilities/SEBURLFilterRegexExpression.cs +++ b/SebWindowsConfig/Utilities/SEBURLFilterRegexExpression.cs @@ -77,7 +77,7 @@ namespace SebWindowsConfig.Utilities if (filterString.Length > 1 && filterString.StartsWith(".")) { // Get host string without the "." prefix - filterString = filterString.Substring(1, filterString.Length); + filterString = filterString.Substring(1); // Get regex for host <*://example.com> (without possible subdomains) return RegexForFilterString(filterString); }