SEBWIN-314: Fixed issues with legacy URL filter implementation.

This commit is contained in:
dbuechel 2019-11-22 15:28:05 +01:00
parent 84be7afa97
commit fa9b84ba68
2 changed files with 5 additions and 5 deletions

View file

@ -21,7 +21,7 @@ namespace SebWindowsConfig.Utilities
if (!string.IsNullOrEmpty(filterExpressionString)) if (!string.IsNullOrEmpty(filterExpressionString))
{ {
/// Convert Uri to a SEBURLFilterExpression /// Convert Uri to a SEBURLFilterExpression
string splitURLRegexPattern = @"(?:([^\:]*)\:\/\/)?(?:([^\:\@]*)(?:\:([^\@]*))?\@)?(?:([^\/\:]*))?(?:\:([0-9\*]*))?([^\?#]*)?(?:\?([^#]*))?(?:#(.*))?"; string splitURLRegexPattern = @"(?:([^\:]*)\:\/\/)?(?:([^\:\@]*)(?:\:([^\@]*))?\@)?(?:([^\/\:]*))?(?:\:([0-9\*]*))?([^\?#]*)?(?:\?([^#]*))?(?:#(.*))?";
Regex splitURLRegex = new Regex(splitURLRegexPattern); Regex splitURLRegex = new Regex(splitURLRegexPattern);
Match regexMatch = splitURLRegex.Match(filterExpressionString); Match regexMatch = splitURLRegex.Match(filterExpressionString);
if (regexMatch.Success == false) if (regexMatch.Success == false)
@ -34,8 +34,8 @@ namespace SebWindowsConfig.Utilities
this.password = regexMatch.Groups[3].Value; this.password = regexMatch.Groups[3].Value;
this.host = regexMatch.Groups[4].Value; this.host = regexMatch.Groups[4].Value;
// Treat a special case when a query is interpreted as part of the host address // Treat a special case when a query or fragment is interpreted as part of the host address
if (this.host.Contains("?")) if (this.host.Contains("?") || this.host.Contains("#"))
{ {
string splitURLRegexPattern2 = @"([^\?#]*)?(?:\?([^#]*))?(?:#(.*))?"; string splitURLRegexPattern2 = @"([^\?#]*)?(?:\?([^#]*))?(?:#(.*))?";
Regex splitURLRegex2 = new Regex(splitURLRegexPattern2); Regex splitURLRegex2 = new Regex(splitURLRegexPattern2);
@ -64,7 +64,7 @@ namespace SebWindowsConfig.Utilities
this.port = UInt16.Parse(portNumber); 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.query = regexMatch.Groups[7].Value;
this.fragment = regexMatch.Groups[8].Value; this.fragment = regexMatch.Groups[8].Value;
} }

View file

@ -77,7 +77,7 @@ namespace SebWindowsConfig.Utilities
if (filterString.Length > 1 && filterString.StartsWith(".")) if (filterString.Length > 1 && filterString.StartsWith("."))
{ {
// Get host string without the "." prefix // 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) // Get regex for host <*://example.com> (without possible subdomains)
return RegexForFilterString(filterString); return RegexForFilterString(filterString);
} }