| 32 | namespace { |
| 33 | |
| 34 | bool CheckPattern(ValidationContext& context, const NavigableAstNode& node, |
| 35 | int arg_index) { |
| 36 | ABSL_DCHECK(node.expr()->has_call_expr()); |
| 37 | const auto& call_expr = node.expr()->call_expr(); |
| 38 | |
| 39 | const Expr* pattern_expr = nullptr; |
| 40 | |
| 41 | if (call_expr.has_target()) { |
| 42 | if (arg_index == 0) { |
| 43 | pattern_expr = &call_expr.target(); |
| 44 | } else if (call_expr.args().size() > arg_index - 1) { |
| 45 | pattern_expr = &call_expr.args()[arg_index - 1]; |
| 46 | } |
| 47 | } else if (call_expr.args().size() > arg_index) { |
| 48 | pattern_expr = &call_expr.args()[arg_index]; |
| 49 | } |
| 50 | |
| 51 | if (pattern_expr == nullptr || !pattern_expr->has_const_expr()) { |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | const auto& const_expr = pattern_expr->const_expr(); |
| 56 | if (!const_expr.has_string_value()) { |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | absl::string_view pattern_string = const_expr.string_value(); |
| 61 | RE2 re(pattern_string, internal::MakeRE2Options()); |
| 62 | if (!re.ok()) { |
| 63 | context.ReportErrorAt( |
| 64 | pattern_expr->id(), |
| 65 | absl::StrCat("invalid regular expression: ", re.error())); |
| 66 | return false; |
| 67 | } |
| 68 | return true; |
| 69 | } |
| 70 | |
| 71 | } // namespace |
| 72 |
no test coverage detected