@ -126,15 +126,18 @@ const executeComparison =
|
|||||||
case ComparisonOperators.MATCHES_REGEX: {
|
case ComparisonOperators.MATCHES_REGEX: {
|
||||||
const matchesRegex = (a: string | null, b: string | null) => {
|
const matchesRegex = (a: string | null, b: string | null) => {
|
||||||
if (b === '' || !b || !a) return false
|
if (b === '' || !b || !a) return false
|
||||||
if (b.startsWith('/') && b.endsWith('/')) b = b.slice(1, -1)
|
const regex = preprocessRegex(b)
|
||||||
return new RegExp(b).test(a)
|
if (!regex) return false
|
||||||
|
return new RegExp(regex.pattern, regex.flags).test(a)
|
||||||
}
|
}
|
||||||
return compare(matchesRegex, inputValue, value, 'some')
|
return compare(matchesRegex, inputValue, value, 'some')
|
||||||
}
|
}
|
||||||
case ComparisonOperators.NOT_MATCH_REGEX: {
|
case ComparisonOperators.NOT_MATCH_REGEX: {
|
||||||
const matchesRegex = (a: string | null, b: string | null) => {
|
const matchesRegex = (a: string | null, b: string | null) => {
|
||||||
if (b === '' || !b || !a) return false
|
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)
|
return compare(matchesRegex, inputValue, value)
|
||||||
}
|
}
|
||||||
@ -171,3 +174,11 @@ const parseDateOrNumber = (value: string): number => {
|
|||||||
}
|
}
|
||||||
return parsed
|
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