mirror of https://gitee.com/answerdev/answer.git
fix(htmltext): FetchExcerpt if actual string length <= expected string length, no need trim marker
This commit is contained in:
parent
7085cfa7ed
commit
83a78737c3
|
@ -75,11 +75,10 @@ func FetchExcerpt(html, trimMarker string, limit int) (text string) {
|
|||
runeText := []rune(text)
|
||||
if len(runeText) <= limit {
|
||||
text = string(runeText)
|
||||
} else {
|
||||
text = string(runeText[0:limit])
|
||||
return
|
||||
}
|
||||
|
||||
text += trimMarker
|
||||
text = string(runeText[0:limit]) + trimMarker
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,10 @@ func TestFetchExcerpt(t *testing.T) {
|
|||
expected = "hello你好😂..."
|
||||
text = FetchExcerpt("<p>hello你好😂world</p>", "...", 8)
|
||||
assert.Equal(t, expected, text)
|
||||
|
||||
expected = "hello你好"
|
||||
text = FetchExcerpt("<p>hello你好</p>", "...", 8)
|
||||
assert.Equal(t, expected, text)
|
||||
}
|
||||
|
||||
func TestUrlTitle(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue