mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(Switch Node): Fix issue preventing some regex patterns from working (#8422)
This commit is contained in:
@@ -125,6 +125,19 @@ function parseFilterConditionValues(
|
||||
return { ok: true, result: { left: parsedLeftValue.newValue, right: parsedRightValue.newValue } };
|
||||
}
|
||||
|
||||
function parseRegexPattern(pattern: string): RegExp {
|
||||
const regexMatch = (pattern || '').match(new RegExp('^/(.*?)/([gimusy]*)$'));
|
||||
let regex: RegExp;
|
||||
|
||||
if (!regexMatch) {
|
||||
regex = new RegExp((pattern || '').toString());
|
||||
} else {
|
||||
regex = new RegExp(regexMatch[1], regexMatch[2]);
|
||||
}
|
||||
|
||||
return regex;
|
||||
}
|
||||
|
||||
export function executeFilterCondition(
|
||||
condition: FilterConditionValue,
|
||||
filterOptions: FilterOptionsValue,
|
||||
@@ -183,9 +196,9 @@ export function executeFilterCondition(
|
||||
case 'notEndsWith':
|
||||
return !left.endsWith(right);
|
||||
case 'regex':
|
||||
return new RegExp(right).test(left);
|
||||
return parseRegexPattern(right).test(left);
|
||||
case 'notRegex':
|
||||
return !new RegExp(right).test(left);
|
||||
return !parseRegexPattern(right).test(left);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -431,6 +431,7 @@ describe('FilterParameter', () => {
|
||||
{ left: 'any string', right: '[0-9]', expected: false },
|
||||
{ left: 'any string', right: '[a-z]', expected: true },
|
||||
{ left: 'lowercase', right: '[A-Z]', expected: false },
|
||||
{ left: 'foo', right: '/^fo{2}$/g', expected: true },
|
||||
])('string:regex("$left","$right") === $expected', ({ left, right, expected }) => {
|
||||
const result = executeFilter(
|
||||
filterFactory({
|
||||
@@ -454,6 +455,7 @@ describe('FilterParameter', () => {
|
||||
{ left: 'any string', right: '[0-9]', expected: true },
|
||||
{ left: 'any string', right: '[a-z]', expected: false },
|
||||
{ left: 'lowercase', right: '[A-Z]', expected: true },
|
||||
{ left: 'foo', right: '/^fo{2}$/g', expected: false },
|
||||
])('string:notRegex("$left","$right") === $expected', ({ left, right, expected }) => {
|
||||
const result = executeFilter(
|
||||
filterFactory({
|
||||
|
||||
Reference in New Issue
Block a user