|
@@ -2,29 +2,31 @@
|
|
|
// <date></date>
|
|
|
// <description></description>
|
|
|
|
|
|
+using System.Text.RegularExpressions;
|
|
|
+
|
|
|
namespace ERP.Framework.Utils
|
|
|
{
|
|
|
public class UrlUtil
|
|
|
{
|
|
|
- public static bool Match(string pattern, string path)
|
|
|
+ public static bool Match(string route, List<string> whiteList)
|
|
|
{
|
|
|
- string[] patternParts = pattern.Split('*', StringSplitOptions.RemoveEmptyEntries);
|
|
|
-
|
|
|
- int currentIndex = 0;
|
|
|
+ if (!route.EndsWith("/"))
|
|
|
+ {
|
|
|
+ route += "/";
|
|
|
+ }
|
|
|
|
|
|
- foreach (string patternPart in patternParts)
|
|
|
+ foreach (var pattern in whiteList)
|
|
|
{
|
|
|
- int index = path.IndexOf(patternPart, currentIndex, StringComparison.OrdinalIgnoreCase);
|
|
|
+ var regexPattern = "^" + Regex.Escape(pattern).Replace("\\*", ".*") + "$";
|
|
|
+ var regex = new Regex(regexPattern);
|
|
|
|
|
|
- if (index == -1)
|
|
|
+ if (regex.IsMatch(route))
|
|
|
{
|
|
|
- return false;
|
|
|
+ return true;
|
|
|
}
|
|
|
-
|
|
|
- currentIndex = index + patternPart.Length;
|
|
|
}
|
|
|
|
|
|
- return true;
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
}
|