Skip to content

Commit

Permalink
同步/导入弹幕屏蔽词时移除非法正则
Browse files Browse the repository at this point in the history
  • Loading branch information
ywmoyue committed Jun 1, 2024
1 parent 4869602 commit f19f4c6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/BiliLite.UWP/BiliLite.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
</Compile>
<Compile Include="Extensions\ControlsExtensions.cs" />
<Compile Include="Extensions\QrCodeExtensions.cs" />
<Compile Include="Extensions\RegexExtensions.cs" />
<Compile Include="Models\Attributes\SettingDefaultValueAttribute.cs" />
<Compile Include="Models\Attributes\SettingKeyAttribute.cs" />
<Compile Include="Models\Common\Anime\ISeasonItem.cs" />
Expand Down
24 changes: 24 additions & 0 deletions src/BiliLite.UWP/Extensions/RegexExtensions.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
5 changes: 5 additions & 0 deletions src/BiliLite.UWP/Modules/SettingVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ private void ImportDanmakuFilterCore(List<DanmuFilterItem> 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);
Expand Down

0 comments on commit f19f4c6

Please sign in to comment.