From 26b74aefaf5d2a3cd26bd57652fe96a6a20ed034 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Sat, 7 May 2022 16:55:27 +0100 Subject: [bugfix] Fix existing bio text showing as HTML (#531) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix existing bio text showing as HTML - updated replaced mentions to include instance - strips HTML from account source note in Verify handler - update text formatter to use buffers for string writes Signed-off-by: kim * go away linter Signed-off-by: kim * change buf reset location, change html mention tags Signed-off-by: kim * reduce FindLinks code complexity Signed-off-by: kim * fix HTML to text conversion Signed-off-by: kim * Update internal/regexes/regexes.go Co-authored-by: Mina Galić * use improved html2text lib with more options Signed-off-by: kim * fix to produce actual plaintext from html Signed-off-by: kim * fix span tags instead written as space Signed-off-by: kim * performance improvements to regex replacements, fix link replace logic for un-html-ing in the future Signed-off-by: kim * fix tag/mention replacements to use input string, fix link replace to not include scheme Signed-off-by: kim * use matched input string for link replace href text Signed-off-by: kim * remove unused code (to appease linter :sobs:) Signed-off-by: kim * improve hashtagFinger regex to be more compliant Signed-off-by: kim * update breakReplacer to include both unix and windows line endings Signed-off-by: kim * add NoteRaw field to Account to store plaintext account bio, add migration for this, set for sensitive accounts Signed-off-by: kim * drop unnecessary code Signed-off-by: kim * update text package tests to fix logic changes Signed-off-by: kim * add raw note content testing to account update and account verify Signed-off-by: kim * remove unused modules Signed-off-by: kim * fix emoji regex Signed-off-by: kim * fix replacement of hashtags Signed-off-by: kim * update code comment Signed-off-by: kim Co-authored-by: Mina Galić --- internal/text/plain.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'internal/text/plain.go') diff --git a/internal/text/plain.go b/internal/text/plain.go index 453f4dd31..4ef3b3715 100644 --- a/internal/text/plain.go +++ b/internal/text/plain.go @@ -20,12 +20,17 @@ package text import ( "context" - "fmt" "strings" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) +// breakReplacer replaces new-lines with HTML breaks. +var breakReplacer = strings.NewReplacer( + "\r\n", "
", + "\n", "
", +) + func (f *formatter) FromPlain(ctx context.Context, plain string, mentions []*gtsmodel.Mention, tags []*gtsmodel.Tag) string { content := preformat(plain) @@ -42,10 +47,10 @@ func (f *formatter) FromPlain(ctx context.Context, plain string, mentions []*gts content = f.ReplaceMentions(ctx, content, mentions) // replace newlines with breaks - content = strings.ReplaceAll(content, "\n", "
") + content = breakReplacer.Replace(content) // wrap the whole thing in a pee - content = fmt.Sprintf(`

%s

`, content) + content = `

` + content + `

` return postformat(content) } -- cgit v1.2.3