Skip to content

Commit

Permalink
Clarify replace with/by empty string (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbetz committed Aug 22, 2023
1 parent 2de9952 commit 78039f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ext/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ const (
// 'hello hello'.replace('he', 'we', -1) // returns 'wello wello'
// 'hello hello'.replace('he', 'we', 1) // returns 'wello hello'
// 'hello hello'.replace('he', 'we', 0) // returns 'hello hello'
// 'hello hello'.replace('', '_') // returns '_h_e_l_l_o_ _h_e_l_l_o_'
// 'hello hello'.replace('h', '') // returns 'ello ello'
//
// # Split
//
Expand Down Expand Up @@ -514,7 +516,7 @@ func (lib *stringLib) CompileOptions() []cel.EnvOption {
)
}
if lib.version >= 3 {
opts = append( opts,
opts = append(opts,
cel.Function("reverse",
cel.MemberOverload("reverse", []*cel.Type{cel.StringType}, cel.StringType,
cel.UnaryBinding(func(str ref.Val) ref.Val {
Expand Down
2 changes: 2 additions & 0 deletions ext/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ var stringTests = []struct {
{expr: `"{0} days {0} hours".replace("{0}", "2") == "2 days 2 hours"`},
{expr: `"{0} days {0} hours".replace("{0}", "2", 1).replace("{0}", "23") == "2 days 23 hours"`},
{expr: `"1 ©αT taco".replace("αT", "o©α") == "1 ©o©α taco"`},
{expr: `"hello hello".replace("", "_") == "_h_e_l_l_o_ _h_e_l_l_o_"`},
{expr: `"hello hello".replace("h", "") == "ello ello"`},
// Split tests.
{expr: `"hello world".split(" ") == ["hello", "world"]`},
{expr: `"hello world events!".split(" ", 0) == []`},
Expand Down

0 comments on commit 78039f1

Please sign in to comment.