beego: template fund when the start> len(bt)
Showing
2 changed files
with
6 additions
and
0 deletions
| ... | @@ -27,6 +27,9 @@ func Substr(s string, start, length int) string { | ... | @@ -27,6 +27,9 @@ func Substr(s string, start, length int) string { |
| 27 | if start < 0 { | 27 | if start < 0 { |
| 28 | start = 0 | 28 | start = 0 |
| 29 | } | 29 | } |
| 30 | if start > len(bt) { | ||
| 31 | start = start % len(bt) | ||
| 32 | } | ||
| 30 | var end int | 33 | var end int |
| 31 | if (start + length) > (len(bt) - 1) { | 34 | if (start + length) > (len(bt) - 1) { |
| 32 | end = len(bt) | 35 | end = len(bt) | ... | ... |
| ... | @@ -25,6 +25,9 @@ func TestSubstr(t *testing.T) { | ... | @@ -25,6 +25,9 @@ func TestSubstr(t *testing.T) { |
| 25 | if Substr(s, 0, 100) != "012345" { | 25 | if Substr(s, 0, 100) != "012345" { |
| 26 | t.Error("should be equal") | 26 | t.Error("should be equal") |
| 27 | } | 27 | } |
| 28 | if Substr(s, 12, 100) != "012345" { | ||
| 29 | t.Error("should be equal") | ||
| 30 | } | ||
| 28 | } | 31 | } |
| 29 | 32 | ||
| 30 | func TestHtml2str(t *testing.T) { | 33 | func TestHtml2str(t *testing.T) { | ... | ... |
-
Please register or sign in to post a comment