From 809a0075cd4378f198ad4efcc86865776fadfdf2 Mon Sep 17 00:00:00 2001 From: Cameron Moore Date: Sun, 3 Jan 2021 12:01:42 -0600 Subject: [PATCH] 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 --- tpl/strings/strings_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tpl/strings/strings_test.go b/tpl/strings/strings_test.go index d2bd9907704..f3bb82c63a1 100644 --- a/tpl/strings/strings_test.go +++ b/tpl/strings/strings_test.go @@ -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"},