MCPcopy Index your code
hub / github.com/simstudioai/sim / validateRegex

Function validateRegex

apps/sim/lib/guardrails/validate_regex.ts:11–31  ·  view source on GitHub ↗
(inputStr: string, pattern: string)

Source from the content-addressed store, hash-verified

9}
10
11export 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}

Callers 1

executeValidationFunction · 0.90

Calls 1

testMethod · 0.80

Tested by

no test coverage detected