mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
fix(editor): Properly handle mapping of dragged expression if it contains hyphen (#5703)
This commit is contained in:
parent
02e35819ab
commit
7025efe865
|
@ -1,5 +1,5 @@
|
||||||
import { INodeProperties } from 'n8n-workflow';
|
import { INodeProperties } from 'n8n-workflow';
|
||||||
import { getMappedResult } from '../mappingUtils';
|
import { getMappedResult, getMappedExpression } from '../mappingUtils';
|
||||||
|
|
||||||
const RLC_PARAM: INodeProperties = {
|
const RLC_PARAM: INodeProperties = {
|
||||||
displayName: 'Base',
|
displayName: 'Base',
|
||||||
|
@ -199,4 +199,59 @@ describe('Mapping Utils', () => {
|
||||||
expect(getMappedResult(RLC_PARAM, '{{ test }}', '=test')).toEqual('=test {{ test }}');
|
expect(getMappedResult(RLC_PARAM, '{{ test }}', '=test')).toEqual('=test {{ test }}');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('getMappedExpression', () => {
|
||||||
|
it('should generate a mapped expression with simple array path', () => {
|
||||||
|
const input = {
|
||||||
|
nodeName: 'nodeName',
|
||||||
|
distanceFromActive: 2,
|
||||||
|
path: ['sample', 'path'],
|
||||||
|
};
|
||||||
|
const result = getMappedExpression(input);
|
||||||
|
expect(result).toBe('{{ $node.nodeName.json.sample.path }}');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate a mapped expression with mixed array path', () => {
|
||||||
|
const input = {
|
||||||
|
nodeName: 'nodeName',
|
||||||
|
distanceFromActive: 2,
|
||||||
|
path: ['sample', 0, 'path'],
|
||||||
|
};
|
||||||
|
const result = getMappedExpression(input);
|
||||||
|
expect(result).toBe('{{ $node.nodeName.json.sample[0].path }}');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate a mapped expression with special characters in array path', () => {
|
||||||
|
const input = {
|
||||||
|
nodeName: 'nodeName',
|
||||||
|
distanceFromActive: 2,
|
||||||
|
path: ['sample', 'path with-space', 'path-with-hyphen'],
|
||||||
|
};
|
||||||
|
const result = getMappedExpression(input);
|
||||||
|
expect(result).toBe(
|
||||||
|
'{{ $node.nodeName.json.sample["path with-space"]["path-with-hyphen"] }}',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate a mapped expression with various path elements', () => {
|
||||||
|
const input = {
|
||||||
|
nodeName: 'nodeName',
|
||||||
|
distanceFromActive: 1,
|
||||||
|
path: ['propertyName', 'capitalizedName', 'hyphen-prop'],
|
||||||
|
};
|
||||||
|
const result = getMappedExpression(input);
|
||||||
|
expect(result).toBe('{{ $json.propertyName.capitalizedName["hyphen-prop"] }}');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate a mapped expression with a complex path', () => {
|
||||||
|
const input = {
|
||||||
|
nodeName: 'nodeName',
|
||||||
|
distanceFromActive: 1,
|
||||||
|
path: ['propertyName', 'capitalizedName', 'stringVal', 'some-value', 'capitalizedProp'],
|
||||||
|
};
|
||||||
|
const result = getMappedExpression(input);
|
||||||
|
expect(result).toBe(
|
||||||
|
'{{ $json.propertyName.capitalizedName.stringVal["some-value"].capitalizedProp }}',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,7 +6,7 @@ export function generatePath(root: string, path: Array<string | number>): string
|
||||||
return `${accu}[${part}]`;
|
return `${accu}[${part}]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (part.includes(' ') || part.includes('.')) {
|
if (part.includes('-') || part.includes(' ') || part.includes('.')) {
|
||||||
return `${accu}["${part}"]`;
|
return `${accu}["${part}"]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue