mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-12 15:44:06 -08:00
fix(editor): Add safety to prevent undefined errors (#11104)
This commit is contained in:
parent
1d14557461
commit
565b117a52
|
@ -694,7 +694,7 @@ export function useWorkflowHelpers(options: { router: ReturnType<typeof useRoute
|
|||
}
|
||||
|
||||
const workflowId = workflowsStore.workflowId;
|
||||
const path = getWebhookExpressionValue(webhookData, 'path', true, node.name);
|
||||
const path = getWebhookExpressionValue(webhookData, 'path', true, node.name) ?? '';
|
||||
const isFullPath =
|
||||
(getWebhookExpressionValue(
|
||||
webhookData,
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import { ExpressionError } from 'n8n-workflow';
|
||||
import { stringifyExpressionResult, unwrapExpression } from '../expressions';
|
||||
import {
|
||||
removeExpressionPrefix,
|
||||
stringifyExpressionResult,
|
||||
unwrapExpression,
|
||||
} from '../expressions';
|
||||
|
||||
describe('Utils: Expressions', () => {
|
||||
describe('stringifyExpressionResult()', () => {
|
||||
|
@ -43,4 +47,14 @@ describe('Utils: Expressions', () => {
|
|||
expect(unwrapExpression('{{ $json.foo }}')).toBe('$json.foo');
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeExpressionPrefix', () => {
|
||||
it.each([
|
||||
['=expression', 'expression'],
|
||||
['notAnExpression', 'notAnExpression'],
|
||||
[undefined, ''],
|
||||
])('turns "%s" into "%s"', (input, output) => {
|
||||
expect(removeExpressionPrefix(input)).toBe(output);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -16,8 +16,8 @@ export const unwrapExpression = (expr: string) => {
|
|||
return expr.replace(/\{\{(.*)\}\}/, '$1').trim();
|
||||
};
|
||||
|
||||
export const removeExpressionPrefix = (expr: string) => {
|
||||
return expr.startsWith('=') ? expr.slice(1) : expr;
|
||||
export const removeExpressionPrefix = (expr: string | null | undefined) => {
|
||||
return expr?.startsWith('=') ? expr.slice(1) : (expr ?? '');
|
||||
};
|
||||
|
||||
export const isTestableExpression = (expr: string) => {
|
||||
|
|
Loading…
Reference in a new issue