From 695e800b37e6a6b3df353da367661377c0aa0e30 Mon Sep 17 00:00:00 2001 From: Raj Nishtala Date: Thu, 19 Dec 2024 15:35:34 -0500 Subject: [PATCH] fix: Use a default cut string of ' ' when replacement is empty --- pkg/ottl/ottlfuncs/func_trim.go | 3 +++ pkg/ottl/ottlfuncs/func_trim_test.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/ottl/ottlfuncs/func_trim.go b/pkg/ottl/ottlfuncs/func_trim.go index b911b5a0c506..f2193ba43d6d 100644 --- a/pkg/ottl/ottlfuncs/func_trim.go +++ b/pkg/ottl/ottlfuncs/func_trim.go @@ -37,6 +37,9 @@ func trim[K any](target ottl.StringGetter[K], replacement ottl.Optional[string]) if err != nil { return nil, err } + if replacement.IsEmpty() { + return strings.Trim(val, " "), nil + } return strings.Trim(val, replacementString), nil } } diff --git a/pkg/ottl/ottlfuncs/func_trim_test.go b/pkg/ottl/ottlfuncs/func_trim_test.go index 08392ab44fbd..233c28d38536 100644 --- a/pkg/ottl/ottlfuncs/func_trim_test.go +++ b/pkg/ottl/ottlfuncs/func_trim_test.go @@ -50,7 +50,7 @@ func Test_trim(t *testing.T) { }, }, replacement: ottl.Optional[string]{}, - expected: " this is a test ", + expected: "this is a test", shouldError: false, }, {