@ -126,15 +126,18 @@ const executeComparison =
|
||||
case ComparisonOperators.MATCHES_REGEX: {
|
||||
const matchesRegex = (a: string | null, b: string | null) => {
|
||||
if (b === '' || !b || !a) return false
|
||||
if (b.startsWith('/') && b.endsWith('/')) b = b.slice(1, -1)
|
||||
return new RegExp(b).test(a)
|
||||
const regex = preprocessRegex(b)
|
||||
if (!regex) return false
|
||||
return new RegExp(regex.pattern, regex.flags).test(a)
|
||||
}
|
||||
return compare(matchesRegex, inputValue, value, 'some')
|
||||
}
|
||||
case ComparisonOperators.NOT_MATCH_REGEX: {
|
||||
const matchesRegex = (a: string | null, b: string | null) => {
|
||||
if (b === '' || !b || !a) return false
|
||||
return !new RegExp(b).test(a)
|
||||
const regex = preprocessRegex(b)
|
||||
if (!regex) return true
|
||||
return !new RegExp(regex.pattern, regex.flags).test(a)
|
||||
}
|
||||
return compare(matchesRegex, inputValue, value)
|
||||
}
|
||||
@ -171,3 +174,11 @@ const parseDateOrNumber = (value: string): number => {
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
const preprocessRegex = (regex: string) => {
|
||||
const match = regex.match(/^\/([^\/]+)\/([gimuy]*)$/)
|
||||
|
||||
if (!match) return null
|
||||
|
||||
return { pattern: match[1], flags: match[2] }
|
||||
}
|
||||
|
Reference in New Issue
Block a user