Skip to content

Commit

Permalink
修复评论中出现重复av号导致富文本解析失败应用崩溃
Browse files Browse the repository at this point in the history
  • Loading branch information
ywmoyue committed Nov 9, 2023
1 parent bd48ef4 commit 240f0b3
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/BiliLite.UWP/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public static RichTextBlock ToRichTextBlock(this string txt, JObject emote)
{
if (txt != null)
{

//处理特殊字符
input = input.Replace("&", "&");
input = input.Replace("<", "&lt;");
Expand Down Expand Up @@ -358,7 +357,8 @@ private static string HandelVideoID(string input)
if (!Regex.IsMatch(input, @"/[aAbBcC][vV]([a-zA-Z0-9]+)"))
{
//处理AV号
MatchCollection av = Regex.Matches(input, @"[aA][vV](\d+)");
MatchCollection av = Regex.Matches(input, @"[aA][vV](\d+)");
var offset = 0;
foreach (Match item in av)
{
if (keyword.Contains(item.Groups[0].Value))
Expand All @@ -372,11 +372,14 @@ private static string HandelVideoID(string input)
string.Format(
@" CommandParameter=""{1}"" ><TextBlock>{0}</TextBlock></HyperlinkButton></InlineUIContainer>",
item.Groups[0].Value, "bilibili://video/" + item.Groups[0].Value);
input = input.Replace(item.Groups[0].Value, data);
input = input.Remove(item.Index + offset, item.Length);
input = input.Insert(item.Index + offset, data);
offset += data.Length - item.Length;
}

//处理AV号
MatchCollection bv = Regex.Matches(input, @"[bB][vV]([a-zA-Z0-9]{8,})");
offset = 0;
foreach (Match item in bv)
{
if (keyword.Contains(item.Groups[0].Value))
Expand All @@ -390,12 +393,15 @@ private static string HandelVideoID(string input)
string.Format(
@" CommandParameter=""{1}"" ><TextBlock>{0}</TextBlock></HyperlinkButton></InlineUIContainer>",
item.Groups[0].Value, "bilibili://video/" + item.Groups[0].Value);
input = input.Replace(item.Groups[0].Value, data);
input = input.Remove(item.Index + offset, item.Length);
input = input.Insert(item.Index + offset, data);
offset += data.Length - item.Length;
}

//处理CV号

MatchCollection cv = Regex.Matches(input, @"[cC][vV](\d+)");
offset = 0;
foreach (Match item in cv)
{
if (keyword.Contains(item.Groups[0].Value))
Expand All @@ -409,7 +415,9 @@ private static string HandelVideoID(string input)
string.Format(
@" CommandParameter=""{1}"" ><TextBlock>{0}</TextBlock></HyperlinkButton></InlineUIContainer>",
item.Groups[0].Value, "bilibili://article/" + item.Groups[1].Value);
input = input.Replace(item.Groups[0].Value, data);
input = input.Remove(item.Index + offset, item.Length);
input = input.Insert(item.Index + offset, data);
offset += data.Length - item.Length;
}
}

Expand Down

0 comments on commit 240f0b3

Please sign in to comment.