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

fix: validate form inside a form #11947

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-waves-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: validate form inside a form
11 changes: 11 additions & 0 deletions packages/svelte/src/compiler/phases/2-analyze/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,17 @@ const validation = {
}
}

// can't add form to interactive elements because those are also used by the parser
trueadm marked this conversation as resolved.
Show resolved Hide resolved
// 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"code": "node_invalid_placement",
"message": "<form> is invalid inside <form>",
"start": {
"line": 4,
"column": 3
},
"end": {
"line": 6,
"column": 10
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div>
<form>
<div>
<form>
<input />
</form>
</div>
</form>
</div>
Loading