summaryrefslogtreecommitdiff
path: root/op_crates/fetch/21_formdata.js
diff options
context:
space:
mode:
authorLuca Casonato <lucacasonato@yahoo.com>2021-04-20 14:47:22 +0200
committerGitHub <noreply@github.com>2021-04-20 14:47:22 +0200
commit9e6cd91014ac4a0d34556b0d09cbe25e4e0930c6 (patch)
tree4523790510a17676c987039feb03f208a258dc16 /op_crates/fetch/21_formdata.js
parent115197ffb06aad2a3045e8478980ab911b5a5eeb (diff)
chore: align fetch to spec (#10203)
This commit aligns the `fetch` API and the `Request` / `Response` classes belonging to it to the spec. This commit enables all the relevant `fetch` WPT tests. Spec compliance is now at around 90%. Performance is essentially identical now (within 1% of 1.9.0).
Diffstat (limited to 'op_crates/fetch/21_formdata.js')
-rw-r--r--op_crates/fetch/21_formdata.js25
1 files changed, 24 insertions, 1 deletions
diff --git a/op_crates/fetch/21_formdata.js b/op_crates/fetch/21_formdata.js
index 106b67da4..00f97f346 100644
--- a/op_crates/fetch/21_formdata.js
+++ b/op_crates/fetch/21_formdata.js
@@ -442,6 +442,11 @@
* @returns {FormData}
*/
parse() {
+ // Body must be at least 2 boundaries + \r\n + -- on the last boundary.
+ if (this.body.length < (this.boundary.length * 2) + 4) {
+ throw new TypeError("Form data too short to be valid.");
+ }
+
const formData = new FormData();
let headerText = "";
let boundaryIndex = 0;
@@ -525,5 +530,23 @@
return parser.parse();
}
- globalThis.__bootstrap.formData = { FormData, encodeFormData, parseFormData };
+ /**
+ * @param {FormDataEntry[]} entries
+ * @returns {FormData}
+ */
+ function formDataFromEntries(entries) {
+ const fd = new FormData();
+ fd[entryList] = entries;
+ return fd;
+ }
+
+ webidl.converters["FormData"] = webidl
+ .createInterfaceConverter("FormData", FormData);
+
+ globalThis.__bootstrap.formData = {
+ FormData,
+ encodeFormData,
+ parseFormData,
+ formDataFromEntries,
+ };
})(globalThis);