Links rune (#1344)

* shorten links with non-latin properly

* lint: unneeded conversion
This commit is contained in:
Umputun
2022-04-30 12:03:52 -05:00
committed by GitHub
parent 5a6ca7a82b
commit 7cdb006f81
2 changed files with 6 additions and 1 deletions
+2 -1
View File
@@ -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
}
+4
View File
@@ -25,6 +25,10 @@ func TestFormatter_FormatText(t *testing.T) {
"<p><a href=\"http://127.0.0.1/some-long-link/12345/678901234567890\">http://127.0.0." +
"1/some-long-link/12345/6789012...</a></p>\n!converted", "links",
},
{
"something https://amp.dw.com/ru/илон-маск-купил-twitter/a-61590911",
"<p>something <a href=\"https://amp.dw.com/ru/илон-маск-купил-twitter/a-61590911\">https://amp.dw.com/ru/илон-маск-купил-twitter...</a></p>\n!converted", "links",
},
{
"something <img src=\"some.png\"/> _aaa_",
"<p>something <img src=\"some.png\" loading=\"lazy\"/> <em>aaa</em></p>\n!converted",