diff --git a/dom/base/BodyUtil.cpp b/dom/base/BodyUtil.cpp index 8efac6d223d9..c6bb575a6645 100644 --- a/dom/base/BodyUtil.cpp +++ b/dom/base/BodyUtil.cpp @@ -290,6 +290,10 @@ class MOZ_STACK_CLASS FormDataParser { mFilename.SetIsVoid(true); mContentType = "text/plain"_ns; + while (start != end && NS_IsHTTPWhitespace(*start)) { + ++start; + } + // MUST start with boundary. if (!PushOverBoundary(boundaryString, start, end)) { return false; diff --git a/dom/fetch/tests/mochitest.toml b/dom/fetch/tests/mochitest.toml index a6031877b966..3f7692d8561a 100644 --- a/dom/fetch/tests/mochitest.toml +++ b/dom/fetch/tests/mochitest.toml @@ -1,5 +1,11 @@ [DEFAULT] +support-files = [ + "multipart.sjs", +] + ["test_ext_response_constructor.html"] ["test_invalid_header_exception.html"] + +["test_bug1752761.html"] diff --git a/dom/fetch/tests/multipart.sjs b/dom/fetch/tests/multipart.sjs new file mode 100644 index 000000000000..a6a1e5031a75 --- /dev/null +++ b/dom/fetch/tests/multipart.sjs @@ -0,0 +1,32 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +function handleRequest(request, response) { + response.seizePower(); + + response.write("HTTP/1.1 200 OK\r\n"); + response.write("Access-Control-Allow-Origin: *\r\n"); + // See bug 1752761. The extra "\r\n" was the reason why FormDataParser + // could not parse this correctly. + response.write( + "Content-type: multipart/form-data; boundary=boundary\r\n\r\n" + ); + response.write("\r\n"); + response.write("--boundary\r\n"); + response.write( + 'Content-Disposition: form-data; name="file1"; filename="file1.txt"\r\n' + ); + response.write("Content-Type: text/plain\r\n\r\n"); + response.write("Content of file1\r\n"); + response.write("--boundary\r\n"); + response.write( + 'Content-Disposition: form-data; name="file2"; filename="file2.txt"\r\n' + ); + response.write("Content-Type: text/plain\r\n\r\n"); + response.write("Content of file2\r\n"); + response.write("--boundary--\r\n"); + response.write(""); + response.finish(); +} diff --git a/dom/fetch/tests/test_bug1752761.html b/dom/fetch/tests/test_bug1752761.html new file mode 100644 index 000000000000..55bf3e644596 --- /dev/null +++ b/dom/fetch/tests/test_bug1752761.html @@ -0,0 +1,27 @@ + + +
+ +