Bug 540854 - XMLHttpRequest truncates UTF-8 encoded strings containing Code Point 0x00, r=sicking

--HG--
extra : rebase_source : 251c02fe91bf35fe46f0f1e3a829ddb00e889132
This commit is contained in:
Olli Pettay 2010-01-26 15:54:55 +02:00
parent baadb3f6bc
commit aac1a2a936
4 changed files with 73 additions and 1 deletions

View File

@ -2377,8 +2377,11 @@ nsXMLHttpRequest::Send(nsIVariant *aBody)
break;
default:
// try variant string
rv = aBody->GetAsWString(getter_Copies(serial));
PRUnichar* data = nsnull;
PRUint32 len = 0;
rv = aBody->GetAsWStringWithSize(&len, &data);
NS_ENSURE_SUCCESS(rv, rv);
serial.Adopt(data, len);
break;
}

View File

@ -337,6 +337,8 @@ _TEST_FILES = test_bug5141.html \
file_CSP.sjs \
file_CSP_main.html \
file_CSP_main.js \
test_bug540854.html \
bug540854.sjs \
$(NULL)
# Disabled; see bug 492181

View File

@ -0,0 +1,19 @@
const CC = Components.Constructor;
const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream",
"setInputStream");
function handleRequest(request, response)
{
response.setHeader("Content-Type", "text/plain", false);
var body = new BinaryInputStream(request.bodyInputStream);
var avail;
var bytes = [];
while ((avail = body.available()) > 0)
Array.prototype.push.apply(bytes, body.readByteArray(avail));
var data = String.fromCharCode.apply(null, bytes);
response.bodyOutputStream.write(data, data.length);
}

View File

@ -0,0 +1,48 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=540854
-->
<head>
<title>Test for Bug 540854</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=540854">Mozilla Bug 540854</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 540854 **/
var x;
function getUTF8() {
return unescape(encodeURIComponent('\0foo'));
}
function xload() {
is(this.responseText, getUTF8(), "Unexpected responseText!");
SimpleTest.finish();
}
function runTest() {
x = new XMLHttpRequest();
x.open("POST", "bug540854.sjs")
x.onload = xload;
x.send(getUTF8());
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(runTest);
</script>
</pre>
</body>
</html>