feat(n8n Form Node): Add read-only/custom HTML form elements (#12760)

This commit is contained in:
Dana
2025-01-22 13:05:30 +01:00
committed by GitHub
parent 1c7a38f6ba
commit ba8aa39216
5 changed files with 126 additions and 7 deletions

View File

@@ -15,6 +15,7 @@ import {
prepareFormReturnItem,
resolveRawData,
isFormConnected,
sanitizeHtml,
} from '../utils';
describe('FormTrigger, parseFormDescription', () => {
@@ -42,6 +43,29 @@ describe('FormTrigger, parseFormDescription', () => {
});
});
describe('FormTrigger, sanitizeHtml', () => {
it('should remove forbidden HTML tags', () => {
const givenHtml = [
{
html: '<script>alert("hello world")</script>',
expected: '',
},
{
html: '<style>body { color: red; }</style>',
expected: '',
},
{
html: '<input type="text" value="test">',
expected: '',
},
];
givenHtml.forEach(({ html, expected }) => {
expect(sanitizeHtml(html)).toBe(expected);
});
});
});
describe('FormTrigger, formWebhook', () => {
const executeFunctions = mock<IWebhookFunctions>();
executeFunctions.getNode.mockReturnValue({ typeVersion: 2.1 } as any);
@@ -80,6 +104,12 @@ describe('FormTrigger, formWebhook', () => {
acceptFileTypes: '.pdf,.doc',
multipleFiles: false,
},
{
fieldLabel: 'Custom HTML',
fieldType: 'html',
html: '<div>Test HTML</div>',
requiredField: false,
},
];
executeFunctions.getNodeParameter.calledWith('formFields.values').mockReturnValue(formFields);
@@ -134,6 +164,16 @@ describe('FormTrigger, formWebhook', () => {
multipleFiles: '',
placeholder: undefined,
},
{
id: 'field-4',
errorId: 'error-field-4',
label: 'Custom HTML',
inputRequired: '',
defaultValue: '',
placeholder: undefined,
html: '<div>Test HTML</div>',
isHtml: true,
},
],
formSubmittedText: 'Your response has been recorded',
formTitle: 'Test Form',