Skip to content

Commit 78039f1

Browse files
authored
Clarify replace with/by empty string (#820)
1 parent 2de9952 commit 78039f1

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

ext/strings.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ const (
202202
// 'hello hello'.replace('he', 'we', -1) // returns 'wello wello'
203203
// 'hello hello'.replace('he', 'we', 1) // returns 'wello hello'
204204
// 'hello hello'.replace('he', 'we', 0) // returns 'hello hello'
205+
// 'hello hello'.replace('', '_') // returns '_h_e_l_l_o_ _h_e_l_l_o_'
206+
// 'hello hello'.replace('h', '') // returns 'ello ello'
205207
//
206208
// # Split
207209
//
@@ -514,7 +516,7 @@ func (lib *stringLib) CompileOptions() []cel.EnvOption {
514516
)
515517
}
516518
if lib.version >= 3 {
517-
opts = append( opts,
519+
opts = append(opts,
518520
cel.Function("reverse",
519521
cel.MemberOverload("reverse", []*cel.Type{cel.StringType}, cel.StringType,
520522
cel.UnaryBinding(func(str ref.Val) ref.Val {

ext/strings_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ var stringTests = []struct {
8282
{expr: `"{0} days {0} hours".replace("{0}", "2") == "2 days 2 hours"`},
8383
{expr: `"{0} days {0} hours".replace("{0}", "2", 1).replace("{0}", "23") == "2 days 23 hours"`},
8484
{expr: `"1 ©αT taco".replace("αT", "o©α") == "1 ©o©α taco"`},
85+
{expr: `"hello hello".replace("", "_") == "_h_e_l_l_o_ _h_e_l_l_o_"`},
86+
{expr: `"hello hello".replace("h", "") == "ello ello"`},
8587
// Split tests.
8688
{expr: `"hello world".split(" ") == ["hello", "world"]`},
8789
{expr: `"hello world events!".split(" ", 0) == []`},

0 commit comments

Comments
 (0)