From bfbe196d80fbcee381102809c7bd4b1c686d8da1 Mon Sep 17 00:00:00 2001 From: Azhe Kun Date: Sun, 2 Jun 2024 21:41:09 +0700 Subject: [PATCH] fixing cache key --- backend/ZiziBot.Utils/StringUtil.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/ZiziBot.Utils/StringUtil.cs b/backend/ZiziBot.Utils/StringUtil.cs index e7fca8dd..9c0277ee 100644 --- a/backend/ZiziBot.Utils/StringUtil.cs +++ b/backend/ZiziBot.Utils/StringUtil.cs @@ -115,6 +115,7 @@ public static string ForCacheKey(this string url) .Replace("https://", "") .Replace("http://", "") .Replace(".", "-") + .RegexReplaceEval(@"(%20|\s)+", "_") .TrimEnd('_'); return key; @@ -167,6 +168,16 @@ public static string RegexReplace(this string input, string pattern, string repl return Regex.Replace(input, pattern, replacement); } + public static string RegexReplaceEval(this string input, string pattern, string replacement) + { + return Regex.Replace(input, pattern, Eval); + + string Eval(Match m) + { + return replacement; + } + } + public static string RegexMatch(this string input, string pattern) { return Regex.Match(input, pattern).Value;