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 } }