From 260a8800a47eb1fcb212ed13941215f5a542df57 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Sat, 28 Sep 2019 19:13:30 -0500 Subject: [PATCH] prevent raw html when color codes are enabled --- WebfrontCore/TagHelpers/ColorCode.cs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/WebfrontCore/TagHelpers/ColorCode.cs b/WebfrontCore/TagHelpers/ColorCode.cs index 52da35df..f3f18455 100644 --- a/WebfrontCore/TagHelpers/ColorCode.cs +++ b/WebfrontCore/TagHelpers/ColorCode.cs @@ -1,10 +1,8 @@ using Microsoft.AspNetCore.Razor.TagHelpers; using SharedLibraryCore; -using System; -using System.Collections.Generic; using System.Linq; +using System.Web; using System.Text.RegularExpressions; -using System.Threading.Tasks; namespace WebfrontCore.TagHelpers { @@ -19,22 +17,28 @@ namespace WebfrontCore.TagHelpers output.TagName = "ColorCode"; output.TagMode = TagMode.StartTagAndEndTag; + + if (Allow) { - string updated = Value; - - foreach (Match match in Regex.Matches(Value, @"\^([0-9]|\:)([^\^]*)")) + var matches = Regex.Matches(Value, @"\^([0-9]|\:)([^\^]*)"); + foreach (Match match in matches) { char colorCode = match.Groups[1].ToString().Last(); - updated = updated.Replace(match.Value, $"{match.Groups[2].ToString()}"); + output.PreContent.AppendHtml($""); + output.PreContent.Append(match.Groups[2].ToString()); + output.PreContent.AppendHtml(""); } - output.PreContent.SetHtmlContent(updated); + if (matches.Count <= 1) + { + output.PreContent.SetContent(Value.StripColors()); + } } else { - output.PreContent.SetHtmlContent(Value.StripColors()); + output.PreContent.SetContent(Value.StripColors()); } } }