diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp index 44564c0a3ac..46d4eb1d635 100644 --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -885,15 +885,9 @@ nsXMLHttpRequest::ConvertBodyToText(nsAString& aOutBuffer) nsresult rv = NS_OK; nsCAutoString dataCharset; - nsCOMPtr document(do_QueryInterface(mDocument)); + nsCOMPtr document(do_QueryInterface(mDocument)); if (document) { - nsAutoString inputEncoding; - document->GetInputEncoding(inputEncoding); - if (DOMStringIsNull(inputEncoding)) { - dataCharset.AssignLiteral("UTF-8"); - } else { - CopyUTF16toUTF8(inputEncoding, dataCharset); - } + dataCharset = document->GetDocumentCharacterSet(); } else { if (NS_FAILED(DetectCharset(dataCharset)) || dataCharset.IsEmpty()) { // MS documentation states UTF-8 is default for responseText @@ -1940,9 +1934,15 @@ nsXMLHttpRequest::Send(nsIVariant *aBody) nsCOMPtr serializer(do_CreateInstance(NS_XMLSERIALIZER_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - nsCOMPtr baseDoc(do_QueryInterface(doc)); - if (baseDoc) { - charset = baseDoc->GetDocumentCharacterSet(); + nsCOMPtr dom3doc(do_QueryInterface(doc)); + if (dom3doc) { + nsAutoString inputEncoding; + dom3doc->GetInputEncoding(inputEncoding); + if (DOMStringIsNull(inputEncoding)) { + charset.AssignLiteral("UTF-8"); + } else { + CopyUTF16toUTF8(inputEncoding, charset); + } } // Serialize to a stream so that the encoding used will diff --git a/content/base/test/Makefile.in b/content/base/test/Makefile.in index 5b8868cbaf0..88edc0512e1 100644 --- a/content/base/test/Makefile.in +++ b/content/base/test/Makefile.in @@ -184,6 +184,7 @@ _TEST_FILES = test_bug5141.html \ file_bug428847-1.xhtml \ file_bug428847-2.xhtml \ test_bug425201.html \ + test_bug431701.html \ test_bug431833.html \ test_bug435425.html \ bug435425.sjs \ diff --git a/content/base/test/test_bug431701.html b/content/base/test/test_bug431701.html new file mode 100644 index 00000000000..4d558dbff73 --- /dev/null +++ b/content/base/test/test_bug431701.html @@ -0,0 +1,120 @@ + + + + + Test for Bug 431701 + + + + + +Mozilla Bug 431701 +

+ +
+
+
+ + + diff --git a/content/xml/document/src/nsXMLDocument.cpp b/content/xml/document/src/nsXMLDocument.cpp index 4a5daf62b3e..f9a836a5fa1 100644 --- a/content/xml/document/src/nsXMLDocument.cpp +++ b/content/xml/document/src/nsXMLDocument.cpp @@ -133,6 +133,9 @@ NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult, doc->SetPrincipal(aPrincipal); doc->SetBaseURI(aBaseURI); + // XMLDocuments get to be UTF-8 by default, unlike the legacy HTML mess + doc->SetDocumentCharacterSet(NS_LITERAL_CSTRING("UTF-8")); + if (aDoctype) { nsCOMPtr tmpNode; rv = doc->AppendChild(aDoctype, getter_AddRefs(tmpNode));