Skip to content

Commit

Permalink
取消不转换专栏动态,转换富文本前判断是否合法xml
Browse files Browse the repository at this point in the history
  • Loading branch information
ywmoyue committed May 3, 2024
1 parent 47ff875 commit b4b8224
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/BiliLite.UWP/Extensions/DynamicParseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using BiliLite.Models.Common;
using BiliLite.Models.Common.UserDynamic;
using BiliLite.Models.Dynamic;
using BiliLite.Models.Exceptions;
using BiliLite.Services;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -118,6 +119,11 @@ public static RichTextBlock UserDynamicStringToRichText(
{1}
<Paragraph>{0}</Paragraph>
</RichTextBlock>", input, titlePara);
if (!xaml.IsXmlString())
{
throw new CustomizedErrorException("不是有效的xml字符串");
}

var p = (RichTextBlock)XamlReader.Load(xaml);
return p;

Expand Down
23 changes: 23 additions & 0 deletions src/BiliLite.UWP/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using Windows.Storage.Streams;
using System.Threading.Tasks;
using System.Linq;
using System.Xml;
using BiliLite.Models.Exceptions;

namespace BiliLite.Extensions
{
Expand Down Expand Up @@ -120,6 +122,10 @@ public static RichTextBlock ToRichTextBlock(this string txt, JObject emote, bool
fontColor == null ? "" : $"Foreground=\"{fontColor}\"",
$"FontWeight=\"{fontWeight}\"",
lowProfilePrefix);
if (!xaml.IsXmlString())
{
throw new CustomizedErrorException("不是有效的xml字符串");
}
var p = (RichTextBlock)XamlReader.Load(xaml);
return p;
}
Expand Down Expand Up @@ -332,6 +338,23 @@ public static string UrlEncode(this string text)
return Uri.EscapeDataString(text);
}

public static bool IsXmlString(this string text)
{
if (string.IsNullOrEmpty(text)) return false;
var detail = text.Trim();
if (!detail.StartsWith("<") && !detail.EndsWith(">")) return false;
var xml = new XmlDocument();
try
{
xml.LoadXml($"<Root>{detail}</Root>");
return true;
}
catch
{
return false;
}
}

#region Private methods

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,6 @@ public RichTextBlock Content
{
try
{
if (CardType == Constants.DynamicTypes.ARTICLE && OpusSummary != null)
{
var text = OpusSummary.Summary.Text.Nodes.Aggregate("", (current, textNode) => current + textNode.RawText);
return text.GetSimpleRichTextBlock();
}
if (Desc != null)
{
return
Expand Down

0 comments on commit b4b8224

Please sign in to comment.