Commit ea6982fc authored by astaxie's avatar astaxie

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

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 {
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)
......
...@@ -25,6 +25,9 @@ func TestSubstr(t *testing.T) { ...@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment