This commit is contained in:
Danny Martini 2026-05-12 14:28:58 +02:00 committed by GitHub
commit 15aa9fb429
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 0 deletions

View File

@ -25,6 +25,12 @@ const normalizeBackslashes = (text: string): string => {
};
export const splitExpression = (expression: string): ExpressionChunk[] => {
// Maintain the "always have an initial text chunk" invariant
// that ExpressionBuilder.getExpressionCode relies on.
if (expression === '') {
return [{ type: 'text', text: '' }];
}
const chunks: ExpressionChunk[] = [];
let searchingFor: 'open' | 'close' = 'open';
let activeRegex = OPEN_BRACKET;

View File

@ -22,6 +22,12 @@ export const escapeCode = (text: string): string => {
};
export const splitExpression = (expression: string): ExpressionChunk[] => {
// Mirror @n8n/tournament's splitExpression: always emit an initial text
// chunk so downstream consumers can rely on chunks[0] being defined.
if (expression === '') {
return [{ type: 'text', text: '' }];
}
const chunks: ExpressionChunk[] = [];
let searchingFor: 'open' | 'close' = 'open';
let activeRegex = OPEN_BRACKET;

View File

@ -69,6 +69,10 @@ describe('Expression Parser', () => {
{ type: 'code', text: ' code.test("}}") ', hasClosingBrackets: true },
]);
});
test('Empty input (CAT-3075)', () => {
expect(splitExpression('')).toEqual([{ type: 'text', text: '' }]);
});
});
describe('Compatible joining', () => {

View File

@ -778,6 +778,14 @@ describe('Expression', () => {
});
});
// CAT-3075: feature parity between legacy and VM engines for empty expressions.
// The legacy engine returns "" via Tournament.execute's empty-input guard;
// the VM engine bypassed that guard and threw
// `TypeError: Cannot read properties of undefined (reading 'text')`.
it('should resolve "=" (empty expression marker) to "" (CAT-3075)', () => {
expect(evaluate('=')).toBe('');
});
describe('additionalKeys', () => {
const node = workflow.nodes.node;