Skip to content

Commit

Permalink
Fix CEL cost handling of zero length replacement strings
Browse files Browse the repository at this point in the history
Kubernetes-commit: f3f88b8e7b51f15c91b4f004ff4ae04ed6b25ac0
  • Loading branch information
jpbetz authored and k8s-publishing-bot committed Aug 22, 2023
1 parent 0404ad2 commit 4d28f48
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/apiserver/schema/cel/compilation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1683,17 +1683,19 @@ func TestCostEstimation(t *testing.T) {
name: "extended library replace",
schemaGenerator: func(max *int64) *schema.Structural {
strType := withMaxLength(primitiveType("string", ""), max)
beforeLen := int64(2)
afterLen := int64(4)
objType := objectType(map[string]schema.Structural{
"str": strType,
"before": strType,
"after": strType,
"before": withMaxLength(primitiveType("string", ""), &beforeLen),
"after": withMaxLength(primitiveType("string", ""), &afterLen),
})
objType = withRule(objType, "self.str.replace(self.before, self.after) == '0123456789'")
objType = withRule(objType, "self.str.replace(self.before, self.after) == 'does not matter'")
return &objType
},
expectedCalcCost: 629152,
setMaxElements: 10,
expectedSetCost: 14,
expectedCalcCost: 629154, // cost is based on the result size of the replace() call
setMaxElements: 4,
expectedSetCost: 12,
},
{
name: "extended library split",
Expand Down

0 comments on commit 4d28f48

Please sign in to comment.