From 030ba2894f3e9f9442b4bbf83fec09bda1ca88c5 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Mon, 7 Nov 2016 21:27:14 +0100 Subject: Add tests for EllipsisString() and fix bug if param length < 3 --- modules/base/tool.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'modules/base/tool.go') diff --git a/modules/base/tool.go b/modules/base/tool.go index ff072f857f..9177cfe193 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -462,7 +462,10 @@ func Subtract(left interface{}, right interface{}) interface{} { // EllipsisString returns a truncated short string, // it appends '...' in the end of the length of string is too large. func EllipsisString(str string, length int) string { - if len(str) < length { + if length <= 3 { + return "..." + } + if len(str) <= length { return str } return str[:length-3] + "..." -- cgit v1.2.3