From 4dcd67f71b59232530d6816d85ef404d2d03d179 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Sun, 20 Dec 2020 23:43:17 +0100 Subject: [PATCH] Escape title --- Commands.cs | 5 +++-- Utils.cs | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Commands.cs b/Commands.cs index 3f5edf1..24691f0 100644 --- a/Commands.cs +++ b/Commands.cs @@ -43,7 +43,7 @@ namespace RSSBot { { string url = args[1].Value; long chatId = message.Chat.Id; - RssBotFeed feed = new RssBotFeed(url); + RssBotFeed feed = new(url); await Bot.BotClient.SendChatActionAsync(message.Chat, ChatAction.Typing); @@ -196,7 +196,7 @@ namespace RSSBot { List feeds = Bot.RssBotFeeds.Where(x => x.Subs.Contains(chatId)).ToList(); - StringBuilder text = new StringBuilder(); + StringBuilder text = new(); if (feeds.Count < 1) { text.Append("❌ Keine Feeds abonniert."); } else { @@ -236,6 +236,7 @@ namespace RSSBot { string postTitle = "Kein Titel"; if (!string.IsNullOrWhiteSpace(entry.Title)) { postTitle = Utils.StripHtml(entry.Title); + postTitle = Utils.EscapeHtml(postTitle); } string postLink = feed.MainLink; diff --git a/Utils.cs b/Utils.cs index 01297d5..be1eb6b 100644 --- a/Utils.cs +++ b/Utils.cs @@ -7,13 +7,20 @@ using Telegram.Bot.Types.Enums; namespace RSSBot { public static class Utils { - private static readonly Regex RegexHtml = new Regex("<.*?>"); + private static readonly Regex RegexHtml = new("<.*?>"); public static string StripHtml(string input) { return RegexHtml.Replace(input, string.Empty).Trim(); } + public static string EscapeHtml(string input) + { + input = input.Replace("<", "<"); + input = input.Replace(">", ">"); + return input; + } + private static string CleanRss(string input) { string[] replacements = {