Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(n8n Form Trigger Node): Form Improvements #12590

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

dana-gill
Copy link
Contributor

@dana-gill dana-gill commented Jan 13, 2025

Summary

  • Allows users to use HTML in Form descriptions and also sanitizes the HTML to prevent Javascript from being executed.
    For this PR, we are only allowing a select number of HTML elements. We can easily add more by adding more to the sanitize options.
  • We are also populating the rendered Form's description metadata with the form description
  • Add OG metadata to improve sharing across the Internet

Node for testing:

{
  "nodes": [
    {
      "parameters": {
        "formTitle": "form",
        "formDescription": "<script>alert('hello world')</script>\n<i>hello</i>",
        "formFields": {
          "values": [
            {
              "fieldLabel": "name"
            },
            {
              "fieldLabel": "age",
              "fieldType": "number",
              "requiredField": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        -100,
        -60
      ],
      "id": "51631ae1-11ac-4289-942d-159e90013470",
      "name": "On form submission",
      "webhookId": "eb1eed7e-5b3e-4582-962f-fd955d9f44f1"
    }
  ],
  "connections": {
    "On form submission": {
      "main": [
        []
      ]
    }
  },
  "pinData": {}
}

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/NODE-2227/sanitize-rendered-html-for-form-descriptions
https://linear.app/n8n/issue/NODE-2228/render-html-for-form-descriptions
https://linear.app/n8n/issue/NODE-2226/description-parameter-html-formatting
https://linear.app/n8n/issue/NODE-2237/form-title-and-form-description-metadata

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@dana-gill dana-gill changed the title Render HTML for Form descriptions feat(Form Node): Render HTML for Form descriptions Jan 13, 2025
@dana-gill dana-gill marked this pull request as ready for review January 13, 2025 18:18
@dana-gill dana-gill force-pushed the node-2228-html-form-description branch from ff40c69 to 4c6ac47 Compare January 13, 2025 18:18
@dana-gill dana-gill changed the title feat(Form Node): Render HTML for Form descriptions Form Node: Render HTML for Form descriptions Jan 13, 2025
@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team node/improvement New feature or request labels Jan 13, 2025
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@michael-radency michael-radency left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, some suggestions:

  • update parameter description to mention that field accepts HTML
  • add 'target' and 'rel' to allowedAttributes
  • extend allowedTags by 'u', 'sub', 'sup', 'code', 'pre', 'span', 'br'

is there a way to tell if not allowed attributes/tags used? if so worth adding post execution hint

@michael-radency michael-radency changed the title Form Node: Render HTML for Form descriptions feat(n8n Form Trigger Node): Render HTML for Form descriptions Jan 14, 2025
@dana-gill
Copy link
Contributor Author

is there a way to tell if not allowed attributes/tags used? if so worth adding post execution hint

I think we would be able to do this by doing something like context.getNodeParameter('formDescription', '') === sanitize(context.getNodeParameter('formDescription', '')) so this is possible.

Do you have an idea of the best way to add the post execution hint? From my understanding, formWebhook is called when the Form is rendered.

@michael-radency
Copy link
Contributor

is there a way to tell if not allowed attributes/tags used? if so worth adding post execution hint

I think we would be able to do this by doing something like context.getNodeParameter('formDescription', '') === sanitize(context.getNodeParameter('formDescription', '')) so this is possible.

Do you have an idea of the best way to add the post execution hint? From my understanding, formWebhook is called when the Form is rendered.

never mind, I just tested - NodeExecutionOutput hints does not work with trigger and we do not have helper to sanitize HTML in expressions, so we could not define displayCondition in node's hints property either

@dana-gill dana-gill force-pushed the node-2228-html-form-description branch from 4c6ac47 to e7c95d5 Compare January 14, 2025 09:58
Copy link
Contributor

@michael-radency michael-radency left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

Copy link

cypress bot commented Jan 14, 2025

n8n    Run #8756

Run Properties:  status check failed Failed #8756  •  git commit 5285dd15a0: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 dana-gill 🗃️ e2e/*
Project n8n
Branch Review node-2228-html-form-description
Run status status check failed Failed #8756
Run duration 04m 15s
Commit git commit 5285dd15a0: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 dana-gill 🗃️ e2e/*
Committer Dana Lee
View all properties for this run ↗︎

Test results
Tests that failed  Failures 4
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 277
View all changes introduced in this branch ↗︎

Tests for review

Failed  30-langchain.cy.ts • 2 failed tests

View Output Video

Test Artifacts
Langchain Integration > should add and use Manual Chat Trigger node together with Agent node Test Replay Screenshots Video
Langchain Integration > should render runItems for sub-nodes and allow switching between them Test Replay Screenshots Video
Failed  19-execution.cy.ts • 2 failed tests

View Output Video

Test Artifacts
Execution > should send proper payload for manual node run Test Replay Screenshots Video
Execution > should successfully execute partial executions with nodes attached to the second output Test Replay Screenshots Video
Failed  6-code-node.cy.ts • 0 failed tests

View Output

Test Artifacts
Failed  45-workflow-selector-parameter.cy.ts • 0 failed tests

View Output

Test Artifacts
Failed  41-editors.cy.ts • 0 failed tests

View Output

Test Artifacts

The first 5 failed specs are shown, see all 52 specs in Cypress Cloud.

Flakiness  e2e/12-canvas.cy.ts • 1 flaky test

View Output Video

Test Artifacts
Canvas Node Manipulation and Navigation > should preserve connections after rename & node-view switch Test Replay Screenshots Video

Copy link
Contributor

✅ All Cypress E2E specs passed

@dana-gill dana-gill force-pushed the node-2228-html-form-description branch 2 times, most recently from e7c95d5 to 61f9c14 Compare January 14, 2025 15:53
@dana-gill dana-gill changed the title feat(n8n Form Trigger Node): Render HTML for Form descriptions feat(n8n Form Trigger Node): Form Improvements Jan 14, 2025
@dana-gill dana-gill force-pushed the node-2228-html-form-description branch from 61f9c14 to 5285dd1 Compare January 14, 2025 15:58
Copy link
Contributor

@michael-radency michael-radency left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have separate parameter in options for form description metatada with fallback to description?

packages/nodes-base/nodes/Form/utils.ts Show resolved Hide resolved
@dana-gill
Copy link
Contributor Author

dana-gill commented Jan 15, 2025

should we have separate parameter in options for form description metatada with fallback to description?

I thought about doing that especially during this Slack conversation. I get the feeling that we would want to do this as part of an initiative to allow users to set metadata themselves since that would require a bit more specing (I think it was suggested to maybe use a fixedCollection as well). I also added it under Various Requests in this doc. As a result, I thought of taking a leaner and less invasive approach since having to add an additional field would require touching many parts of the Form node -- at least 3-4 functions, multiple test cases, and the *.d.ts files. I thought, "If adding this one extra parameter takes this much work, maybe it's worth waiting until allowing users to set metadata so that we can use time wisely." Let me know if you think this makes sense :)

Copy link
Contributor

@michael-radency michael-radency left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

⚠️ Some Cypress E2E specs are failing, please fix them before merging

@dana-gill dana-gill force-pushed the node-2228-html-form-description branch from dd08e15 to 80be105 Compare January 17, 2025 17:19
@dana-gill dana-gill force-pushed the node-2228-html-form-description branch from 80be105 to 29d7f70 Compare January 17, 2025 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team node/improvement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants