diff --git a/dom/xhr/XMLHttpRequestMainThread.cpp b/dom/xhr/XMLHttpRequestMainThread.cpp index 110ff3202623..5dc99de52bb8 100644 --- a/dom/xhr/XMLHttpRequestMainThread.cpp +++ b/dom/xhr/XMLHttpRequestMainThread.cpp @@ -2776,16 +2776,19 @@ nsresult XMLHttpRequestMainThread::SendInternal(const BodyExtractorBase* aBody, uploadContentType = defaultContentType; } else if (aBodyIsDocumentOrString && StaticPrefs::dom_xhr_standard_content_type_normalization()) { - UniquePtr parsed = CMimeType::Parse(uploadContentType); - if (parsed && parsed->HasParameter(kLiteralString_charset)) { - parsed->SetParameterValue(kLiteralString_charset, - kLiteralString_UTF_8); - parsed->Serialize(uploadContentType); + UniquePtr contentTypeRecord = + CMimeType::Parse(uploadContentType); + nsAutoCString charset; + if (contentTypeRecord && + contentTypeRecord->GetParameterValue(kLiteralString_charset, + charset) && + !charset.EqualsIgnoreCase("utf-8")) { + contentTypeRecord->SetParameterValue(kLiteralString_charset, + kLiteralString_UTF_8); + contentTypeRecord->Serialize(uploadContentType); } - } - - // We don't want to set a charset for streams. - if (!charset.IsEmpty()) { + } else if (!charset.IsEmpty()) { + // We don't want to set a charset for streams. // Replace all case-insensitive matches of the charset in the // content-type with the correct case. RequestHeaders::CharsetIterator iter(uploadContentType); diff --git a/dom/xhr/tests/test_XHRSendData.html b/dom/xhr/tests/test_XHRSendData.html index 653e3e5ca17e..78aa72548276 100644 --- a/dom/xhr/tests/test_XHRSendData.html +++ b/dom/xhr/tests/test_XHRSendData.html @@ -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: "\nhi", @@ -162,7 +162,7 @@ tests = [{ body: null, { body: testDoc2, contentType: "foo/bar; charset=uTf-8", resBody: "\ntext", - 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), diff --git a/modules/libpref/init/StaticPrefList.h b/modules/libpref/init/StaticPrefList.h index 02da4fac5d84..6804e1567232 100644 --- a/modules/libpref/init/StaticPrefList.h +++ b/modules/libpref/init/StaticPrefList.h @@ -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. diff --git a/testing/web-platform/meta/xhr/send-content-type-charset.htm.ini b/testing/web-platform/meta/xhr/send-content-type-charset.htm.ini deleted file mode 100644 index 5853a3796501..000000000000 --- a/testing/web-platform/meta/xhr/send-content-type-charset.htm.ini +++ /dev/null @@ -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 - diff --git a/toolkit/modules/tests/xpcshell/test_Http.js b/toolkit/modules/tests/xpcshell/test_Http.js index 88f1c8c0ce6e..b55aa6bd7092 100644 --- a/toolkit/modules/tests/xpcshell/test_Http.js +++ b/toolkit/modules/tests/xpcshell/test_Http.js @@ -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;