From b4b8224b48964d103532dd324268a25a1eec3056 Mon Sep 17 00:00:00 2001 From: ywmoyue Date: Fri, 3 May 2024 11:42:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88=E4=B8=8D=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E4=B8=93=E6=A0=8F=E5=8A=A8=E6=80=81=EF=BC=8C=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E5=AF=8C=E6=96=87=E6=9C=AC=E5=89=8D=E5=88=A4=E6=96=AD=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=90=88=E6=B3=95xml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/DynamicParseExtensions.cs | 6 +++++ .../Extensions/StringExtensions.cs | 23 +++++++++++++++++++ .../UserDynamic/DynamicV2ItemViewModel.cs | 5 ---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/BiliLite.UWP/Extensions/DynamicParseExtensions.cs b/src/BiliLite.UWP/Extensions/DynamicParseExtensions.cs index 69aa4e33..4bb1ead3 100644 --- a/src/BiliLite.UWP/Extensions/DynamicParseExtensions.cs +++ b/src/BiliLite.UWP/Extensions/DynamicParseExtensions.cs @@ -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; @@ -118,6 +119,11 @@ public static RichTextBlock UserDynamicStringToRichText( {1} {0} ", input, titlePara); + if (!xaml.IsXmlString()) + { + throw new CustomizedErrorException("不是有效的xml字符串"); + } + var p = (RichTextBlock)XamlReader.Load(xaml); return p; diff --git a/src/BiliLite.UWP/Extensions/StringExtensions.cs b/src/BiliLite.UWP/Extensions/StringExtensions.cs index 6ff692b5..289cfc80 100644 --- a/src/BiliLite.UWP/Extensions/StringExtensions.cs +++ b/src/BiliLite.UWP/Extensions/StringExtensions.cs @@ -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 { @@ -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; } @@ -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($"{detail}"); + return true; + } + catch + { + return false; + } + } + #region Private methods /// diff --git a/src/BiliLite.UWP/ViewModels/UserDynamic/DynamicV2ItemViewModel.cs b/src/BiliLite.UWP/ViewModels/UserDynamic/DynamicV2ItemViewModel.cs index d233185d..8f662708 100644 --- a/src/BiliLite.UWP/ViewModels/UserDynamic/DynamicV2ItemViewModel.cs +++ b/src/BiliLite.UWP/ViewModels/UserDynamic/DynamicV2ItemViewModel.cs @@ -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