ea6982fc by astaxie

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

1 parent a3f40234
...@@ -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) {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!