mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08: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:
parent
c5245dd387
commit
0b123ce05e
|
@ -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)) {
|
||||
|
|
Loading…
Reference in a new issue