Skip to content

Commit 4d28f48

Browse files
jpbetzk8s-publishing-bot
authored andcommitted
Fix CEL cost handling of zero length replacement strings
Kubernetes-commit: f3f88b8e7b51f15c91b4f004ff4ae04ed6b25ac0
1 parent 0404ad2 commit 4d28f48

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pkg/apiserver/schema/cel/compilation_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,17 +1683,19 @@ func TestCostEstimation(t *testing.T) {
16831683
name: "extended library replace",
16841684
schemaGenerator: func(max *int64) *schema.Structural {
16851685
strType := withMaxLength(primitiveType("string", ""), max)
1686+
beforeLen := int64(2)
1687+
afterLen := int64(4)
16861688
objType := objectType(map[string]schema.Structural{
16871689
"str": strType,
1688-
"before": strType,
1689-
"after": strType,
1690+
"before": withMaxLength(primitiveType("string", ""), &beforeLen),
1691+
"after": withMaxLength(primitiveType("string", ""), &afterLen),
16901692
})
1691-
objType = withRule(objType, "self.str.replace(self.before, self.after) == '0123456789'")
1693+
objType = withRule(objType, "self.str.replace(self.before, self.after) == 'does not matter'")
16921694
return &objType
16931695
},
1694-
expectedCalcCost: 629152,
1695-
setMaxElements: 10,
1696-
expectedSetCost: 14,
1696+
expectedCalcCost: 629154, // cost is based on the result size of the replace() call
1697+
setMaxElements: 4,
1698+
expectedSetCost: 12,
16971699
},
16981700
{
16991701
name: "extended library split",

0 commit comments

Comments
 (0)