Bug 1454325 - update XHR upload content-type handling to match the spec. r=baku

update XHR upload content-type handling to match the spec

Differential Revision: https://phabricator.services.mozilla.com/D23251

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Thomas Wisniewski 2019-03-19 19:34:39 +00:00
Родитель f4c412f218
Коммит 8518ed6826
5 изменённых файлов: 16 добавлений и 33 удалений

Просмотреть файл

@ -2776,16 +2776,19 @@ nsresult XMLHttpRequestMainThread::SendInternal(const BodyExtractorBase* aBody,
uploadContentType = defaultContentType;
} else if (aBodyIsDocumentOrString &&
StaticPrefs::dom_xhr_standard_content_type_normalization()) {
UniquePtr<CMimeType> parsed = CMimeType::Parse(uploadContentType);
if (parsed && parsed->HasParameter(kLiteralString_charset)) {
parsed->SetParameterValue(kLiteralString_charset,
UniquePtr<CMimeType> contentTypeRecord =
CMimeType::Parse(uploadContentType);
nsAutoCString charset;
if (contentTypeRecord &&
contentTypeRecord->GetParameterValue(kLiteralString_charset,
charset) &&
!charset.EqualsIgnoreCase("utf-8")) {
contentTypeRecord->SetParameterValue(kLiteralString_charset,
kLiteralString_UTF_8);
parsed->Serialize(uploadContentType);
contentTypeRecord->Serialize(uploadContentType);
}
}
} else if (!charset.IsEmpty()) {
// We don't want to set a charset for streams.
if (!charset.IsEmpty()) {
// Replace all case-insensitive matches of the charset in the
// content-type with the correct case.
RequestHeaders::CharsetIterator iter(uploadContentType);

Просмотреть файл

@ -124,7 +124,7 @@ tests = [{ body: null,
{ body: "hi",
contentType: "foo/bar; charset=uTf-8",
resBody: "hi",
resContentType: "foo/bar;charset=UTF-8",
resContentType: "foo/bar; charset=uTf-8",
},
{ body: testDoc1,
resBody: "<!-- comment -->\n<out>hi</out>",
@ -162,7 +162,7 @@ tests = [{ body: null,
{ body: testDoc2,
contentType: "foo/bar; charset=uTf-8",
resBody: "<!-- doc 2 -->\n<res>text</res>",
resContentType: "foo/bar;charset=UTF-8",
resContentType: "foo/bar; charset=uTf-8",
},
{ //will trigger a redirect test server-side
body: ("TEST_REDIRECT_STR&url=" + window.location.host + window.location.pathname),

Просмотреть файл

@ -483,11 +483,10 @@ VARCACHE_PREF(
)
// Enable content type normalization of XHR uploads via MIME Sniffing standard
// Disabled for now in bz1499136
VARCACHE_PREF(
"dom.xhr.standard_content_type_normalization",
dom_xhr_standard_content_type_normalization,
RelaxedAtomicBool, false
RelaxedAtomicBool, true
)
// Block multiple external protocol URLs in iframes per single event.

Просмотреть файл

@ -1,19 +0,0 @@
[send-content-type-charset.htm]
[charset with space that is UTF-8 does not change]
expected: FAIL
[charset in double quotes with backslashes that is UTF-8 does not change]
expected: FAIL
[If charset= param is UTF-8 (case-insensitive), it should not be changed (bogus charset)]
expected: FAIL
[If charset= param is UTF-8 (case-insensitive), it should not be changed]
expected: FAIL
[charset in double quotes that is UTF-8 does not change]
expected: FAIL
[charset with trailing space that is UTF-8 does not change]
expected: FAIL

Просмотреть файл

@ -18,7 +18,7 @@ const kPostPath = "/post";
const kPostUrl = kBaseUrl + kPostPath;
const kPostDataSent = [["foo", "bar"], ["complex", "!*()@"]];
const kPostDataReceived = "foo=bar&complex=%21%2A%28%29%40";
const kPostMimeTypeReceived = "application/x-www-form-urlencoded;charset=UTF-8";
const kPostMimeTypeReceived = "application/x-www-form-urlencoded; charset=utf-8";
const kJsonPostPath = "/json_post";
const kJsonPostUrl = kBaseUrl + kJsonPostPath;