diff --git a/.changeset/breezy-waves-camp.md b/.changeset/breezy-waves-camp.md new file mode 100644 index 0000000000..a324706d9c --- /dev/null +++ b/.changeset/breezy-waves-camp.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: validate form inside a form diff --git a/packages/svelte/src/compiler/phases/2-analyze/validation.js b/packages/svelte/src/compiler/phases/2-analyze/validation.js index 51bb4d85fd..e54828375e 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/validation.js +++ b/packages/svelte/src/compiler/phases/2-analyze/validation.js @@ -568,6 +568,17 @@ const validation = { } } + // can't add form to interactive elements because those are also used by the parser + // to check for the last auto-closing parent. + if (node.name === 'form') { + const path = context.path; + for (let parent of path) { + if (parent.type === 'RegularElement' && parent.name === 'form') { + e.node_invalid_placement(node, `<${node.name}>`, parent.name); + } + } + } + if (interactive_elements.has(node.name)) { const path = context.path; for (let parent of path) { diff --git a/packages/svelte/tests/validator/samples/invalid-node-placement-4/errors.json b/packages/svelte/tests/validator/samples/invalid-node-placement-4/errors.json new file mode 100644 index 0000000000..8b2e2e67ba --- /dev/null +++ b/packages/svelte/tests/validator/samples/invalid-node-placement-4/errors.json @@ -0,0 +1,14 @@ +[ + { + "code": "node_invalid_placement", + "message": "
is invalid inside ", + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 6, + "column": 10 + } + } +] diff --git a/packages/svelte/tests/validator/samples/invalid-node-placement-4/input.svelte b/packages/svelte/tests/validator/samples/invalid-node-placement-4/input.svelte new file mode 100644 index 0000000000..93c3f86c00 --- /dev/null +++ b/packages/svelte/tests/validator/samples/invalid-node-placement-4/input.svelte @@ -0,0 +1,9 @@ +
+ +
+ + + +
+ +