From 2af0fe51c6d2c0455d8a22185eda621029cce777 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Thu, 30 Aug 2018 08:27:20 -0700 Subject: [PATCH] Twitter widget properly unescapes HTML entities --- twitter/widget.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/twitter/widget.go b/twitter/widget.go index d93f70d9..1da55322 100644 --- a/twitter/widget.go +++ b/twitter/widget.go @@ -2,6 +2,7 @@ package twitter import ( "fmt" + "html" "regexp" "github.com/dustin/go-humanize" @@ -66,9 +67,12 @@ func (widget *Widget) displayName(tweet Tweet) string { return tweet.User.ScreenName } -func (widget *Widget) highlightText(text string) string { +func (widget *Widget) formatText(text string) string { result := text + // Convert HTML entities + result = html.UnescapeString(result) + // RT indicator rtRegExp := regexp.MustCompile(`^RT`) result = rtRegExp.ReplaceAllString(result, "[olive]${0}[white::-]") @@ -89,7 +93,7 @@ func (widget *Widget) highlightText(text string) string { } func (widget *Widget) format(tweet Tweet) string { - body := widget.highlightText(tweet.Text) + body := widget.formatText(tweet.Text) name := widget.displayName(tweet) var attribution string