diff --git a/internal/lang/functions_test.go b/internal/lang/functions_test.go index b18493c8cd..f2a6f738c4 100644 --- a/internal/lang/functions_test.go +++ b/internal/lang/functions_test.go @@ -323,6 +323,36 @@ func TestFunctions(t *testing.T) { `endswith("hello world", "hello")`, cty.False, }, + { + `endswith("hello world", "")`, + cty.True, + // Completely empty suffix value ( "" ) + // will always evaluate to true for all strings. + }, + { + `endswith("hello world", " ")`, + cty.False, + }, + { + `endswith("", "")`, + cty.True, + }, + { + `endswith("", " ")`, + cty.False, + }, + { + `endswith(" ", "")`, + cty.True, + }, + { + `endswith("", "hello")`, + cty.False, + }, + { + `endswith(" ", "hello")`, + cty.False, + }, }, "file": { @@ -836,6 +866,36 @@ func TestFunctions(t *testing.T) { `startswith("hello world", "world")`, cty.False, }, + { + `startswith("hello world", "")`, + cty.True, + // Completely empty prefix value ( "" ) + // will always evaluate to true for all strings. + }, + { + `startswith("hello world", " ")`, + cty.False, + }, + { + `startswith("", "")`, + cty.True, + }, + { + `startswith("", " ")`, + cty.False, + }, + { + `startswith(" ", "")`, + cty.True, + }, + { + `startswith("", "hello")`, + cty.False, + }, + { + `startswith(" ", "hello")`, + cty.False, + }, }, "strrev": {