From 7cdb006f81319d40307bfec5b8d1552a7f1a7971 Mon Sep 17 00:00:00 2001 From: Umputun Date: Sat, 30 Apr 2022 12:03:52 -0500 Subject: [PATCH] Links rune (#1344) * shorten links with non-latin properly * lint: unneeded conversion --- backend/app/store/formatter.go | 3 ++- backend/app/store/formatter_test.go | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/app/store/formatter.go b/backend/app/store/formatter.go index 0522eef9..e44cd114 100644 --- a/backend/app/store/formatter.go +++ b/backend/app/store/formatter.go @@ -83,7 +83,8 @@ func (f *CommentFormatter) shortenAutoLinks(commentHTML string, max int) (resHTM if host == "" { return } - short := href[:max-3] + + short := string([]rune(href)[:max-3]) if len(short) < len(host) { short = host } diff --git a/backend/app/store/formatter_test.go b/backend/app/store/formatter_test.go index 6517ecbb..90e7067c 100644 --- a/backend/app/store/formatter_test.go +++ b/backend/app/store/formatter_test.go @@ -25,6 +25,10 @@ func TestFormatter_FormatText(t *testing.T) { "

http://127.0.0." + "1/some-long-link/12345/6789012...

\n!converted", "links", }, + { + "something https://amp.dw.com/ru/илон-маск-купил-twitter/a-61590911", + "

something https://amp.dw.com/ru/илон-маск-купил-twitter...

\n!converted", "links", + }, { "something _aaa_", "

something aaa

\n!converted",