MCPcopy Create free account
hub / github.com/cel-expr/cel-go / decRegexProgramSizeLimit

Function decRegexProgramSizeLimit

interpreter/decorators.go:174–201  ·  view source on GitHub ↗
(limit int)

Source from the content-addressed store, hash-verified

172}
173
174func decRegexProgramSizeLimit(limit int) InterpretableDecoratorV2 {
175 return func(i InterpretableV2) (InterpretableV2, error) {
176 if limit <= 0 {
177 return i, nil
178 }
179 call, ok := i.(InterpretableCall)
180 if !ok {
181 return i, nil
182 }
183 if !isRegexFunction(call.Function(), call.OverloadID()) || len(call.Args()) < 2 {
184 return i, nil
185 }
186 regexArg := call.Args()[1]
187 if constVal, isConst := regexArg.(InterpretableConst); isConst {
188 if pattern, ok := constVal.Value().(types.String); ok {
189 sz, err := types.RegexProgramSize(string(pattern))
190 if err != nil {
191 return i, nil
192 }
193 if sz > limit {
194 return nil, fmt.Errorf("regex program size %d exceeds limit of %d", sz, limit)
195 }
196 }
197 return i, nil
198 }
199 return &regexLimitCall{InterpretableCall: call, limit: limit}, nil
200 }
201}
202
203func isRegexFunction(fn, overload string) bool {
204 switch fn {

Callers 1

RegexProgramSizeLimitFunction · 0.85

Calls 6

RegexProgramSizeFunction · 0.92
isRegexFunctionFunction · 0.85
FunctionMethod · 0.65
OverloadIDMethod · 0.65
ArgsMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected