mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
tpl: Do not return errors in substr for out-of-bounds cases
Most other substr implementations don't error out in out-of-bounds cases but simply return an empty string (or a value that's printed as an empty string). We'll follow their lead and not exit template execution. Allow the user decide what to do with the empty result. Fixes #8113
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
788e50ad3a
commit
8a26ab0bc5
@@ -451,9 +451,9 @@ func TestSubstr(t *testing.T) {
|
||||
{"abcdef", -3, 1, "d"},
|
||||
{"abcdef", 0, -1, "abcde"},
|
||||
{"abcdef", 2, -1, "cde"},
|
||||
{"abcdef", 4, -4, false},
|
||||
{"abcdef", 7, 1, false},
|
||||
{"abcdef", 6, nil, false},
|
||||
{"abcdef", 4, -4, ""},
|
||||
{"abcdef", 7, 1, ""},
|
||||
{"abcdef", 6, nil, ""},
|
||||
{"abcdef", 1, 100, "bcdef"},
|
||||
{"abcdef", -100, 3, "abc"},
|
||||
{"abcdef", -3, -1, "de"},
|
||||
@@ -476,6 +476,7 @@ func TestSubstr(t *testing.T) {
|
||||
{"abcdef", "doo", nil, false},
|
||||
{"abcdef", "doo", "doo", false},
|
||||
{"abcdef", 1, "doo", false},
|
||||
{"", 0, nil, ""},
|
||||
} {
|
||||
|
||||
var result string
|
||||
@@ -491,7 +492,7 @@ func TestSubstr(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(err, qt.IsNil, qt.Commentf("%v", test))
|
||||
c.Check(result, qt.Equals, test.expect, qt.Commentf("%v", test))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user