diff --git a/src/BiliLite.UWP/BiliLite.UWP.csproj b/src/BiliLite.UWP/BiliLite.UWP.csproj index c46dd6e8..3b629933 100644 --- a/src/BiliLite.UWP/BiliLite.UWP.csproj +++ b/src/BiliLite.UWP/BiliLite.UWP.csproj @@ -157,6 +157,7 @@ + diff --git a/src/BiliLite.UWP/Extensions/RegexExtensions.cs b/src/BiliLite.UWP/Extensions/RegexExtensions.cs new file mode 100644 index 00000000..30a65cc7 --- /dev/null +++ b/src/BiliLite.UWP/Extensions/RegexExtensions.cs @@ -0,0 +1,24 @@ +using System; +using System.Text.RegularExpressions; + +namespace BiliLite.Extensions +{ + public static class RegexExtensions + { + public static bool IsValidRegex(this string regexString) + { + if (string.IsNullOrEmpty(regexString)) return false; + + try + { + var regex = new Regex(regexString); + return true; + } + catch (Exception) + { + // 语法不正确的正则表达式会导致ArgumentException异常 + return false; + } + } + } +} diff --git a/src/BiliLite.UWP/Modules/SettingVM.cs b/src/BiliLite.UWP/Modules/SettingVM.cs index 47a29950..40d92fc6 100644 --- a/src/BiliLite.UWP/Modules/SettingVM.cs +++ b/src/BiliLite.UWP/Modules/SettingVM.cs @@ -216,6 +216,11 @@ private void ImportDanmakuFilterCore(List filterList) ShieldRegulars.Clear(); foreach (var item in ls) { + if (!item.IsValidRegex()) + { + logger.Warn("非法正则表达式: " + item); + continue; + } ShieldRegulars.Add(item); } SettingService.SetValue(SettingConstants.VideoDanmaku.SHIELD_REGULAR, ShieldRegulars);