(inputStr: string, pattern: string)
| 9 | } |
| 10 | |
| 11 | export function validateRegex(inputStr: string, pattern: string): ValidationResult { |
| 12 | let regex: RegExp |
| 13 | try { |
| 14 | regex = new RegExp(pattern) |
| 15 | } catch (error: any) { |
| 16 | return { passed: false, error: `Invalid regex pattern: ${error.message}` } |
| 17 | } |
| 18 | |
| 19 | if (!safe(pattern)) { |
| 20 | return { |
| 21 | passed: false, |
| 22 | error: 'Regex pattern rejected: potentially unsafe (catastrophic backtracking)', |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | const match = regex.test(inputStr) |
| 27 | if (match) { |
| 28 | return { passed: true } |
| 29 | } |
| 30 | return { passed: false, error: 'Input does not match regex pattern' } |
| 31 | } |
no test coverage detected