1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 17:00:55 +00:00

beego: template fund when the start> len(bt)

This commit is contained in:
astaxie 2014-08-05 23:52:06 +08:00
parent a3f40234ca
commit ea6982fcea
2 changed files with 6 additions and 0 deletions

View File

@ -27,6 +27,9 @@ func Substr(s string, start, length int) string {
if start < 0 { if start < 0 {
start = 0 start = 0
} }
if start > len(bt) {
start = start % len(bt)
}
var end int var end int
if (start + length) > (len(bt) - 1) { if (start + length) > (len(bt) - 1) {
end = len(bt) end = len(bt)

View File

@ -25,6 +25,9 @@ func TestSubstr(t *testing.T) {
if Substr(s, 0, 100) != "012345" { if Substr(s, 0, 100) != "012345" {
t.Error("should be equal") t.Error("should be equal")
} }
if Substr(s, 12, 100) != "012345" {
t.Error("should be equal")
}
} }
func TestHtml2str(t *testing.T) { func TestHtml2str(t *testing.T) {