summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/fetch/21_formdata.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/ext/fetch/21_formdata.js b/ext/fetch/21_formdata.js
index 5532cc5a3..34103858f 100644
--- a/ext/fetch/21_formdata.js
+++ b/ext/fetch/21_formdata.js
@@ -393,9 +393,19 @@
* @returns {FormData}
*/
parse() {
- // Body must be at least 2 boundaries + \r\n + -- on the last boundary.
+ // To have fields 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 decodedBody = core.decode(this.body);
+ const lastBoundary = this.boundary + "--";
+ // check if it's an empty valid form data
+ if (
+ decodedBody === lastBoundary ||
+ decodedBody === lastBoundary + "\r\n"
+ ) {
+ return new FormData();
+ }
+ throw new TypeError("Unable to parse body as form data.");
}
const formData = new FormData();