Links rune (#1344)
* shorten links with non-latin properly * lint: unneeded conversion
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user