зеркало из https://github.com/mozilla/pjs.git
Bug 669938: nsIJSON::decodeFromStream fails for streams containing fewer than 4 bytes, r=jwalden
This commit is contained in:
Родитель
161f941efc
Коммит
ac0603fae4
|
@ -545,9 +545,10 @@ nsJSONListener::OnStopRequest(nsIRequest *aRequest, nsISupports *aContext,
|
|||
{
|
||||
nsresult rv;
|
||||
|
||||
// This can happen with short UTF-8 messages
|
||||
// This can happen with short UTF-8 messages (<4 bytes)
|
||||
if (!mSniffBuffer.IsEmpty()) {
|
||||
rv = ProcessBytes(mSniffBuffer.get(), mSniffBuffer.Length());
|
||||
// Just consume mSniffBuffer
|
||||
rv = ProcessBytes(nsnull, 0);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
|
@ -617,6 +618,9 @@ nsJSONListener::ProcessBytes(const char* aBuffer, PRUint32 aByteLength)
|
|||
buffer[2] != 0x00 && buffer[3] != 0x00) {
|
||||
charset = "UTF-8";
|
||||
}
|
||||
} else {
|
||||
// Not enough bytes to sniff, assume UTF-8
|
||||
charset = "UTF-8";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -635,6 +639,9 @@ nsJSONListener::ProcessBytes(const char* aBuffer, PRUint32 aByteLength)
|
|||
mSniffBuffer.Truncate();
|
||||
}
|
||||
|
||||
if (!aBuffer)
|
||||
return NS_OK;
|
||||
|
||||
if (mNeedsConverter) {
|
||||
rv = ConsumeConverted(aBuffer, aByteLength);
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -23,4 +23,7 @@ function run_test()
|
|||
var x = read_file("decodeFromStream-01.json");
|
||||
do_check_eq(x["JSON Test Pattern pass3"]["The outermost value"], "must be an object or array.");
|
||||
do_check_eq(x["JSON Test Pattern pass3"]["In this test"], "It is an object.");
|
||||
|
||||
x = read_file("decodeFromStream-small.json");
|
||||
do_check_eq(x.toSource(), "({})", "empty object parsed");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче