diff --git a/backend/app/store/comment_test.go b/backend/app/store/comment_test.go index 3c712766..f84f570f 100644 --- a/backend/app/store/comment_test.go +++ b/backend/app/store/comment_test.go @@ -38,6 +38,10 @@ func TestComment_Sanitize(t *testing.T) { inp: Comment{Text: "blah & & 123 — —"}, out: Comment{Text: `blah & & 123 — —`}, }, + { + inp: Comment{Text: "blah & & 123 — —"}, + out: Comment{Text: `blah & & 123 — —`}, + }, } for n, tt := range tbl { diff --git a/backend/app/store/formatter.go b/backend/app/store/formatter.go index cfd0ff96..b3b52c31 100644 --- a/backend/app/store/formatter.go +++ b/backend/app/store/formatter.go @@ -49,6 +49,7 @@ func (f *CommentFormatter) FormatText(txt string) (res string) { }) res = string(bf.Run([]byte(txt), bf.WithExtensions(mdExt), bf.WithRenderer(rend))) + res = f.unEscape(res) for _, conv := range f.converters { res = conv.Convert(res) @@ -90,3 +91,16 @@ func (f *CommentFormatter) shortenAutoLinks(commentHTML string, max int) (resHTM } return resHTML } + +func (f *CommentFormatter) unEscape(txt string) (res string) { + elems := []struct { + from, to string + }{ + {`—`, "—"}, + } + res = txt + for _, e := range elems { + res = strings.Replace(res, e.from, e.to, -1) + } + return res +} diff --git a/backend/app/store/formatter_test.go b/backend/app/store/formatter_test.go index bea2184c..52b34961 100644 --- a/backend/app/store/formatter_test.go +++ b/backend/app/store/formatter_test.go @@ -14,17 +14,23 @@ func (m mockConverter) Convert(text string) string { return text + "!converted" func TestFormatter_FormatText(t *testing.T) { tbl := []struct { in, out string + name string }{ - {"", "!converted"}, - {"12345 abc", "
12345 abc
\n!converted"}, - {"**xyz** _aaa_ - \"sfs\"", "xyz aaa – «sfs»
\n!converted"}, + {"", "!converted", "empty"}, + {"12345 abc", "12345 abc
\n!converted", "simple"}, + {"**xyz** _aaa_ - \"sfs\"", "xyz aaa – «sfs»
\n!converted", "format"}, { - "http://127.0.0.1/some-long-link/12345/678901234567890", "http://127.0.0.1/some-long-link/12345/6789012...
\n!converted", + "http://127.0.0.1/some-long-link/12345/678901234567890", + "http://127.0.0." + + "1/some-long-link/12345/6789012...
\n!converted", "links", }, + {"— not translated #354", "— not translated #354
\n!converted", "mdash"}, } f := NewCommentFormatter(mockConverter{}) - for n, tt := range tbl { - assert.Equal(t, tt.out, f.FormatText(tt.in), "check #%d", n) + for _, tt := range tbl { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, tt.out, f.FormatText(tt.in)) + }) } }