Bug 562137. Use the UTF-8 decoder to decode UTF-8 instead of just assuming that it really is UTF-8. r=sicking

This commit is contained in:
Boris Zbarsky 2010-05-05 14:18:04 -04:00
parent 99ce80bfab
commit e19f8c4e1a
4 changed files with 40 additions and 5 deletions

View File

@ -1157,17 +1157,16 @@ nsXMLHttpRequest::ConvertBodyToText(nsAString& aOutBuffer)
}
}
// XXXbz is the charset ever "ASCII" as opposed to "us-ascii"?
if (dataCharset.EqualsLiteral("ASCII")) {
CopyASCIItoUTF16(mResponseBody, mResponseBodyUnicode);
aOutBuffer = mResponseBodyUnicode;
return NS_OK;
}
if (dataCharset.EqualsLiteral("UTF-8")) {
CopyUTF8toUTF16(mResponseBody, mResponseBodyUnicode);
aOutBuffer = mResponseBodyUnicode;
return NS_OK;
}
// can't fast-path UTF-8 using CopyUTF8toUTF16, since above we assumed UTF-8
// by default and CopyUTF8toUTF16 will stop if it encounters bytes that aren't
// valid UTF-8. So we have to do the whole unicode decoder thing.
nsCOMPtr<nsICharsetConverterManager> ccm =
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);

View File

@ -381,6 +381,8 @@ _TEST_FILES = test_bug5141.html \
test_bug346485.html \
test_bug560780.html \
test_bug562652.html \
test_bug562137.html \
file_bug562137.txt \
$(NULL)
# This test fails on the Mac for some reason

View File

@ -0,0 +1 @@
I have nbsp

View File

@ -0,0 +1,33 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=562137
-->
<head>
<title>Test for Bug 562137</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=562137">Mozilla Bug 562137</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 562137 **/
var myStr = "I\ufffdhave\ufffdnbsp\n";
var xhr = new XMLHttpRequest();
xhr.open("GET", "file_bug562137.txt", false);
xhr.send();
is(xhr.responseText, myStr);
</script>
</pre>
</body>
</html>