From 11efaf854d8f5108d38c4c7ffa175deb95bfc216 Mon Sep 17 00:00:00 2001 From: httpjamesm Date: Thu, 29 Dec 2022 13:09:25 -0500 Subject: [PATCH] feat: comment text to HTML with sanitization --- src/types/comment.go | 4 +++- src/utils/comments.go | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/types/comment.go b/src/types/comment.go index 950105e..118a547 100644 --- a/src/types/comment.go +++ b/src/types/comment.go @@ -1,7 +1,9 @@ package types +import "html/template" + type FilteredComment struct { - Text string + Text template.HTML Timestamp string AuthorName string AuthorURL string diff --git a/src/utils/comments.go b/src/utils/comments.go index fbade7e..15d7ae0 100644 --- a/src/utils/comments.go +++ b/src/utils/comments.go @@ -2,6 +2,7 @@ package utils import ( "anonymousoverflow/src/types" + "html/template" "github.com/PuerkitoBio/goquery" ) @@ -40,7 +41,7 @@ func FindAndReturnComments(inHtml string, postLayout *goquery.Selection) (commen commentTimestamp := commentBody.Find("span.relativetime-clean").Text() newFilteredComment := types.FilteredComment{ - Text: commentCopy, + Text: template.HTML(commentCopy), Timestamp: commentTimestamp, AuthorName: commentAuthor.Text(), AuthorURL: commentAuthorURL,