Allow variables with dots and keys (#17361)
Fixes https://github.com/twentyhq/private-issues/issues/410#issuecomment-3781085655 Currently, JSON keys with spaces like { "toto toto": 123 } are rejected with "JSON keys cannot contain spaces" error. This is problematic for HTTP requests and webhook triggers where users cannot control the response structure. We use Handlebars to eval variables, segment-literal bracket notation to escape keys with special characters: Normal: {{step.normalKey}} With spaces: `{{step.[key with space]}}` So we simply need to wrap segments with spaces with brackets. This PR: - Create shared path utilities to wrap the variable segments when needed - Use it in all variable generation places - Remove the restrictions This body is now supported: <img width="609" height="457" alt="Capture d’écran 2026-01-22 à 16 10 13" src="https://github.com/user-attachments/assets/e7653c0a-df1e-49af-9c9a-4b7d59a99726" />
This commit is contained in:
@@ -129,4 +129,54 @@ describe('resolveInput', () => {
|
||||
}),
|
||||
).toBe('{ "a": "str" }');
|
||||
});
|
||||
|
||||
describe('bracket notation for keys with special characters', () => {
|
||||
it('should resolve variables with keys containing spaces', () => {
|
||||
const contextWithSpaces = {
|
||||
step: {
|
||||
'key with space': 'value from space key',
|
||||
},
|
||||
};
|
||||
expect(resolveInput('{{step.[key with space]}}', contextWithSpaces)).toBe(
|
||||
'value from space key',
|
||||
);
|
||||
});
|
||||
|
||||
it('should resolve nested variables with keys containing spaces', () => {
|
||||
const contextWithSpaces = {
|
||||
step: {
|
||||
'first key': {
|
||||
'nested key': 'nested value',
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(
|
||||
resolveInput('{{step.[first key].[nested key]}}', contextWithSpaces),
|
||||
).toBe('nested value');
|
||||
});
|
||||
|
||||
it('should resolve mixed normal and bracket notation paths', () => {
|
||||
const contextWithMixed = {
|
||||
step: {
|
||||
normal: {
|
||||
'key with space': 42,
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(
|
||||
resolveInput('{{step.normal.[key with space]}}', contextWithMixed),
|
||||
).toBe(42);
|
||||
});
|
||||
|
||||
it('should resolve variables with keys containing dots', () => {
|
||||
const contextWithDots = {
|
||||
step: {
|
||||
'key.with.dots': 'dotted value',
|
||||
},
|
||||
};
|
||||
expect(resolveInput('{{step.[key.with.dots]}}', contextWithDots)).toBe(
|
||||
'dotted value',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user