From 7d646a828a363db3d11ece2c2c2c9c560494e95c Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sat, 1 Jun 2024 17:26:53 -0400 Subject: feat(strings): Update strings.Indent to error on bad input instead of silently doing nothing (#2089) Signed-off-by: Dave Henderson --- strings/strings_fuzz_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'strings/strings_fuzz_test.go') diff --git a/strings/strings_fuzz_test.go b/strings/strings_fuzz_test.go index 4a1fa671..52472c4a 100644 --- a/strings/strings_fuzz_test.go +++ b/strings/strings_fuzz_test.go @@ -6,6 +6,7 @@ import ( "unicode" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func FuzzIndent(f *testing.F) { @@ -16,7 +17,19 @@ func FuzzIndent(f *testing.F) { f.Add(15, "\n0", "\n0") f.Fuzz(func(t *testing.T, width int, indent, s string) { - out := Indent(width, indent, s) + out, err := Indent(width, indent, s) + + if width <= 0 { + require.Error(t, err) + return + } + + if strings.Contains(indent, "\n") { + require.Error(t, err) + return + } + + require.NoError(t, err) // out should be equal to s when both have the indent character // completely removed. -- cgit v1.2.3