Bug 1752761 - Fix FormDataParser issue due to extra \r\n, r=sunil
Differential Revision: https://phabricator.services.mozilla.com/D216149
This commit is contained in:
@@ -290,6 +290,10 @@ class MOZ_STACK_CLASS FormDataParser {
|
|||||||
mFilename.SetIsVoid(true);
|
mFilename.SetIsVoid(true);
|
||||||
mContentType = "text/plain"_ns;
|
mContentType = "text/plain"_ns;
|
||||||
|
|
||||||
|
while (start != end && NS_IsHTTPWhitespace(*start)) {
|
||||||
|
++start;
|
||||||
|
}
|
||||||
|
|
||||||
// MUST start with boundary.
|
// MUST start with boundary.
|
||||||
if (!PushOverBoundary(boundaryString, start, end)) {
|
if (!PushOverBoundary(boundaryString, start, end)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
|
|
||||||
|
support-files = [
|
||||||
|
"multipart.sjs",
|
||||||
|
]
|
||||||
|
|
||||||
["test_ext_response_constructor.html"]
|
["test_ext_response_constructor.html"]
|
||||||
|
|
||||||
["test_invalid_header_exception.html"]
|
["test_invalid_header_exception.html"]
|
||||||
|
|
||||||
|
["test_bug1752761.html"]
|
||||||
|
|||||||
32
dom/fetch/tests/multipart.sjs
Normal file
32
dom/fetch/tests/multipart.sjs
Normal file
@@ -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();
|
||||||
|
}
|
||||||
27
dom/fetch/tests/test_bug1752761.html
Normal file
27
dom/fetch/tests/test_bug1752761.html
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Test bug1752761</title>
|
||||||
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
|
||||||
|
<script>
|
||||||
|
add_task(async function () {
|
||||||
|
const response = await fetch("multipart.sjs", {
|
||||||
|
method: 'GET',
|
||||||
|
mode: 'cors'
|
||||||
|
});
|
||||||
|
|
||||||
|
let p = response.formData().then(function (data) {
|
||||||
|
SimpleTest.ok(data instanceof FormData, "Valid FormData extracted.");
|
||||||
|
});
|
||||||
|
await p;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p id="display"></p>
|
||||||
|
<div id="content" style="display: none"></div>
|
||||||
|
<pre id="test"></pre>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user