Bug 883296: returning empty object instead of null when decoding zero length data in Octet.decodeMultiple. r=gene

This commit is contained in:
Patrick Wang 2013-06-17 19:33:57 +08:00
Родитель 6191808691
Коммит 2f848ffdc6
1 изменённых файлов: 27 добавлений и 29 удалений

Просмотреть файл

@ -239,7 +239,7 @@ this.Octet = {
throw new RangeError(); throw new RangeError();
} }
if (end == data.offset) { if (end == data.offset) {
return null; return [];
} }
let result; let result;
@ -2291,40 +2291,38 @@ this.PduHelper = {
let octetArray = Octet.decodeMultiple(data, contentEnd); let octetArray = Octet.decodeMultiple(data, contentEnd);
let content = null; let content = null;
if (octetArray) { let charset = headers["content-type"].params &&
let charset = headers["content-type"].params && headers["content-type"].params.charset
headers["content-type"].params.charset ? headers["content-type"].params.charset.charset
? headers["content-type"].params.charset.charset : null;
: null;
let mimeType = headers["content-type"].media; let mimeType = headers["content-type"].media;
if (mimeType) { if (mimeType) {
if (mimeType == "application/smil") { if (mimeType == "application/smil") {
// If the content is a SMIL type, convert it to a string. // If the content is a SMIL type, convert it to a string.
// We hope to save and expose the SMIL content in a string way. // We hope to save and expose the SMIL content in a string way.
content = this.decodeStringContent(octetArray, charset); content = this.decodeStringContent(octetArray, charset);
} else if (mimeType.indexOf("text/") == 0 && charset != "utf-8") { } else if (mimeType.indexOf("text/") == 0 && charset != "utf-8") {
// If the content is a "text/plain" type, we have to make sure // If the content is a "text/plain" type, we have to make sure
// the encoding of the blob content should always be "utf-8". // the encoding of the blob content should always be "utf-8".
let tmpStr = this.decodeStringContent(octetArray, charset); let tmpStr = this.decodeStringContent(octetArray, charset);
let encoder = new TextEncoder("UTF-8"); let encoder = new TextEncoder("UTF-8");
content = new Blob([encoder.encode(tmpStr)], {type : mimeType}); content = new Blob([encoder.encode(tmpStr)], {type : mimeType});
// Make up the missing encoding info. // Make up the missing encoding info.
if (!headers["content-type"].params) { if (!headers["content-type"].params) {
headers["content-type"].params = {}; headers["content-type"].params = {};
}
if (!headers["content-type"].params.charset) {
headers["content-type"].params.charset = {};
}
headers["content-type"].params.charset.charset = "utf-8";
} }
if (!headers["content-type"].params.charset) {
headers["content-type"].params.charset = {};
}
headers["content-type"].params.charset.charset = "utf-8";
} }
}
if (!content) { if (!content) {
content = new Blob([octetArray], {type : mimeType}); content = new Blob([octetArray], {type : mimeType});
}
} }
parts[i] = { parts[i] = {