mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-26 22:04:32 +02:00
tpl: Refactor and fix substr logic
Fix miscalculations when start is negative. Results should now match PHP substr. Fixes #7993
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
32d4bf68da
commit
64789fb5dc
@@ -441,8 +441,11 @@ func TestSubstr(t *testing.T) {
|
||||
}{
|
||||
{"abc", 1, 2, "bc"},
|
||||
{"abc", 0, 1, "a"},
|
||||
{"abcdef", -1, 2, "ef"},
|
||||
{"abcdef", -3, 3, "bcd"},
|
||||
{"abcdef", -1, 2, "f"},
|
||||
{"abcdef", -3, 3, "def"},
|
||||
{"abcdef", -1, nil, "f"},
|
||||
{"abcdef", -2, nil, "ef"},
|
||||
{"abcdef", -3, 1, "d"},
|
||||
{"abcdef", 0, -1, "abcde"},
|
||||
{"abcdef", 2, -1, "cde"},
|
||||
{"abcdef", 4, -4, false},
|
||||
@@ -480,12 +483,12 @@ func TestSubstr(t *testing.T) {
|
||||
}
|
||||
|
||||
if b, ok := test.expect.(bool); ok && !b {
|
||||
c.Assert(err, qt.Not(qt.IsNil))
|
||||
c.Assert(err, qt.Not(qt.IsNil), qt.Commentf("%v", test))
|
||||
continue
|
||||
}
|
||||
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(result, qt.Equals, test.expect)
|
||||
c.Assert(result, qt.Equals, test.expect, qt.Commentf("%v", test))
|
||||
}
|
||||
|
||||
_, err = ns.Substr("abcdef")
|
||||
|
Reference in New Issue
Block a user