mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(core): Fix expression extension misdetection (#5219)
* 🐛 Narrow down check * fix: converted expression extension check loop into regex * fix: remove greedy string check * fix: re-add string spliting regex Co-authored-by: Valya Bullions <valya@n8n.io>
This commit is contained in:
@@ -314,11 +314,15 @@ export class Expression {
|
||||
}
|
||||
|
||||
extendSyntax(bracketedExpression: string): string {
|
||||
if (!hasExpressionExtension(bracketedExpression) || hasNativeMethod(bracketedExpression))
|
||||
return bracketedExpression;
|
||||
|
||||
const chunks = splitExpression(bracketedExpression);
|
||||
|
||||
const codeChunks = chunks
|
||||
.filter((c) => c.type === 'code')
|
||||
.map((c) => c.text.replace(/("|').*?("|')/, '').trim());
|
||||
|
||||
if (!codeChunks.some(hasExpressionExtension) || hasNativeMethod(bracketedExpression))
|
||||
return bracketedExpression;
|
||||
|
||||
const extendedChunks = chunks.map((chunk): ExpressionChunk => {
|
||||
if (chunk.type === 'code') {
|
||||
const output = extendTransform(chunk.text);
|
||||
|
||||
@@ -41,14 +41,17 @@ const EXPRESSION_EXTENSION_METHODS = Array.from(
|
||||
...Object.keys(arrayExtensions.functions),
|
||||
...Object.keys(objectExtensions.functions),
|
||||
...Object.keys(genericExtensions),
|
||||
'$if',
|
||||
]),
|
||||
);
|
||||
|
||||
const EXPRESSION_EXTENSION_REGEX = new RegExp(
|
||||
`(\\$if|\\.(${EXPRESSION_EXTENSION_METHODS.join('|')}))\\s*\\(`,
|
||||
);
|
||||
|
||||
const isExpressionExtension = (str: string) => EXPRESSION_EXTENSION_METHODS.some((m) => m === str);
|
||||
|
||||
export const hasExpressionExtension = (str: string): boolean =>
|
||||
EXPRESSION_EXTENSION_METHODS.some((m) => str.includes(m));
|
||||
EXPRESSION_EXTENSION_REGEX.test(str);
|
||||
|
||||
export const hasNativeMethod = (method: string): boolean => {
|
||||
if (hasExpressionExtension(method)) {
|
||||
|
||||
Reference in New Issue
Block a user