Skip to content

Commit

Permalink
fix: input name overriding form method and action checks (#8471)
Browse files Browse the repository at this point in the history
* change form.method to form.getAttribute

* add changeset

* normalise form.getAttribute value

* remove helper method and use HTMLFormElement.prototype

* change form.action to use HTMLFormElement.prototype

* revert unneccesary form cloning from runtime/client.js

* tidy up

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
  • Loading branch information
eltigerchino and dummdidumm authored Jan 13, 2023
1 parent f09ad43 commit 37ed70b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tidy-plants-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: avoid input name clobbering form method check
6 changes: 5 additions & 1 deletion packages/kit/src/runtime/app/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export function deserialize(result) {

/** @type {import('$app/forms').enhance} */
export function enhance(form, submit = () => {}) {
if (DEV && form.method !== 'post') {
if (
DEV &&
/** @type {HTMLFormElement} */ (HTMLFormElement.prototype.cloneNode.call(form)).method !==
'post'
) {
throw new Error('use:enhance can only be used on <form> fields with method="POST"');
}

Expand Down

0 comments on commit 37ed70b

Please sign in to comment.