mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 19:32:15 +00:00
feat(n8n Form Node): Add read-only/custom HTML form elements (#12760)
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user