* Safe regex test: rejects patterns that are oversized, contain nested quantifiers * (the primary cause of catastrophic backtracking), or are syntactically invalid.
(pattern: string, value: string)
| 48 | * (the primary cause of catastrophic backtracking), or are syntactically invalid. |
| 49 | */ |
| 50 | function safeRegexTest(pattern: string, value: string): boolean { |
| 51 | if (pattern.length > MAX_REGEX_LENGTH) return false |
| 52 | if (hasNestedQuantifier(pattern)) return false |
| 53 | try { |
| 54 | return new RegExp(pattern).test(value) |
| 55 | } catch { |
| 56 | return false |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Check if a ground value matches a comparison value using the same matrix |
no test coverage detected