(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues)
| 543 | } |
| 544 | |
| 545 | func (v regexProgramSizeLimitValidator) Validate(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues) { |
| 546 | if v.limit <= 0 { |
| 547 | return |
| 548 | } |
| 549 | root := ast.NavigateAST(a) |
| 550 | callExprs := ast.MatchDescendants(root, ast.KindMatcher(ast.CallKind)) |
| 551 | for _, call := range callExprs { |
| 552 | c := call.AsCall() |
| 553 | fn := c.FunctionName() |
| 554 | if !isRegexFunctionName(fn) { |
| 555 | continue |
| 556 | } |
| 557 | args := c.Args() |
| 558 | var regexArgIndex int |
| 559 | if (fn == overloads.Matches || fn == "matches") && c.Target() != nil { |
| 560 | regexArgIndex = 0 |
| 561 | } else { |
| 562 | regexArgIndex = 1 |
| 563 | } |
| 564 | if len(args) <= regexArgIndex { |
| 565 | continue |
| 566 | } |
| 567 | arg := args[regexArgIndex] |
| 568 | if arg.Kind() != ast.LiteralKind { |
| 569 | continue |
| 570 | } |
| 571 | pattern, ok := arg.AsLiteral().Value().(string) |
| 572 | if !ok { |
| 573 | continue |
| 574 | } |
| 575 | sz, err := types.RegexProgramSize(pattern) |
| 576 | if err != nil { |
| 577 | // Invalid regex literals are handled in a different validator. |
| 578 | continue |
| 579 | } |
| 580 | if sz > v.limit { |
| 581 | iss.ReportErrorAtID(arg.ID(), "regex program size %d exceeds limit of %d", sz, v.limit) |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | func isEmptyRangeComprehension(e ast.NavigableExpr) bool { |
| 587 | if e.Kind() != ast.ComprehensionKind { |
nothing calls this directly
no test coverage detected