From 3d42a4c06483a517e3be8634d6b8f408dbcc0c1f Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:56:12 -0700 Subject: [PATCH] Update pkg/ottl/ottlfuncs/func_trim.go --- pkg/ottl/ottlfuncs/func_trim.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/ottl/ottlfuncs/func_trim.go b/pkg/ottl/ottlfuncs/func_trim.go index f2193ba43d6d..1e4ae51b9a5d 100644 --- a/pkg/ottl/ottlfuncs/func_trim.go +++ b/pkg/ottl/ottlfuncs/func_trim.go @@ -31,15 +31,15 @@ func createTrimFunction[K any](_ ottl.FunctionContext, oArgs ottl.Arguments) (ot } func trim[K any](target ottl.StringGetter[K], replacement ottl.Optional[string]) ottl.ExprFunc[K] { - replacementString := replacement.Get() + replacementString := " " + if !replacement.IsEmpty() { + replacementString = replacement.Get() + } return func(ctx context.Context, tCtx K) (any, error) { val, err := target.Get(ctx, tCtx) if err != nil { return nil, err } - if replacement.IsEmpty() { - return strings.Trim(val, " "), nil - } return strings.Trim(val, replacementString), nil } }