Escape title

This commit is contained in:
Andreas Bielawski 2020-12-20 23:43:17 +01:00
parent e97bea90e9
commit 4dcd67f71b
Signed by untrusted user: Brawl
GPG Key ID: 851D5FF3B79056CA
2 changed files with 11 additions and 3 deletions

View File

@ -43,7 +43,7 @@ namespace RSSBot {
{ {
string url = args[1].Value; string url = args[1].Value;
long chatId = message.Chat.Id; long chatId = message.Chat.Id;
RssBotFeed feed = new RssBotFeed(url); RssBotFeed feed = new(url);
await Bot.BotClient.SendChatActionAsync(message.Chat, ChatAction.Typing); await Bot.BotClient.SendChatActionAsync(message.Chat, ChatAction.Typing);
@ -196,7 +196,7 @@ namespace RSSBot {
List<RssBotFeed> feeds = Bot.RssBotFeeds.Where(x => x.Subs.Contains(chatId)).ToList(); List<RssBotFeed> feeds = Bot.RssBotFeeds.Where(x => x.Subs.Contains(chatId)).ToList();
StringBuilder text = new StringBuilder(); StringBuilder text = new();
if (feeds.Count < 1) { if (feeds.Count < 1) {
text.Append("❌ Keine Feeds abonniert."); text.Append("❌ Keine Feeds abonniert.");
} else { } else {
@ -236,6 +236,7 @@ namespace RSSBot {
string postTitle = "Kein Titel"; string postTitle = "Kein Titel";
if (!string.IsNullOrWhiteSpace(entry.Title)) { if (!string.IsNullOrWhiteSpace(entry.Title)) {
postTitle = Utils.StripHtml(entry.Title); postTitle = Utils.StripHtml(entry.Title);
postTitle = Utils.EscapeHtml(postTitle);
} }
string postLink = feed.MainLink; string postLink = feed.MainLink;

View File

@ -7,13 +7,20 @@ using Telegram.Bot.Types.Enums;
namespace RSSBot { namespace RSSBot {
public static class Utils { public static class Utils {
private static readonly Regex RegexHtml = new Regex("<.*?>"); private static readonly Regex RegexHtml = new("<.*?>");
public static string StripHtml(string input) public static string StripHtml(string input)
{ {
return RegexHtml.Replace(input, string.Empty).Trim(); return RegexHtml.Replace(input, string.Empty).Trim();
} }
public static string EscapeHtml(string input)
{
input = input.Replace("<", "&lt;");
input = input.Replace(">", "&gt;");
return input;
}
private static string CleanRss(string input) private static string CleanRss(string input)
{ {
string[] replacements = { string[] replacements = {