Skip to content

Commit

Permalink
fix: Use a default cut string of ' ' when replacement is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
rnishtala-sumo committed Dec 19, 2024
1 parent 5167e4c commit 695e800
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/ottl/ottlfuncs/func_trim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion pkg/ottl/ottlfuncs/func_trim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand Down

0 comments on commit 695e800

Please sign in to comment.