Bug 883296: returning empty object instead of null when decoding zero length data in Octet.decodeMultiple. r=gene
authorPatrick Wang <kk1fff@patrickz.net>
Mon, 17 Jun 2013 19:33:57 +0800
changeset 135773 1b659b9958cb3ec9efbea6e6545a806616ea3198
parent 135772 0664d639c478a9a52eae77e182742934ff5135cd
child 135774 72fd56a50fe835bda9083197a04e41f395064c49
push idunknown
push userunknown
push dateunknown
reviewersgene
bugs883296
milestone24.0a1
Bug 883296: returning empty object instead of null when decoding zero length data in Octet.decodeMultiple. r=gene
dom/mobilemessage/src/ril/WspPduHelper.jsm
--- a/dom/mobilemessage/src/ril/WspPduHelper.jsm
+++ b/dom/mobilemessage/src/ril/WspPduHelper.jsm
@@ -234,17 +234,17 @@ this.Octet = {
    * @throws RangeError if no enough data to read.
    * @throws TypeError if `data` has neither subarray() nor slice() method.
    */
   decodeMultiple: function decodeMultiple(data, end) {
     if ((end < data.offset) || (end > data.array.length)) {
       throw new RangeError();
     }
     if (end == data.offset) {
-      return null;
+      return [];
     }
 
     let result;
     if (data.array.subarray) {
       result = data.array.subarray(data.offset, end);
     } else if (data.array.slice) {
       result = data.array.slice(data.offset, end);
     } else {
@@ -2286,50 +2286,48 @@ this.PduHelper = {
         let contentType = ContentTypeValue.decode(data);
         headers["content-type"] = contentType;
         headers["content-length"] = contentLen;
 
         headers = this.parseHeaders(data, headersEnd, headers);
 
         let octetArray = Octet.decodeMultiple(data, contentEnd);
         let content = null;
-        if (octetArray) {
-          let charset = headers["content-type"].params &&
-                        headers["content-type"].params.charset
-                      ? headers["content-type"].params.charset.charset
-                      : null;
+        let charset = headers["content-type"].params &&
+                      headers["content-type"].params.charset
+                    ? headers["content-type"].params.charset.charset
+                    : null;
 
-          let mimeType = headers["content-type"].media;
+        let mimeType = headers["content-type"].media;
 
-          if (mimeType) {
-            if (mimeType == "application/smil") {
-              // 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.
-              content = this.decodeStringContent(octetArray, charset);
-            } else if (mimeType.indexOf("text/") == 0 && charset != "utf-8") {
-              // If the content is a "text/plain" type, we have to make sure
-              // the encoding of the blob content should always be "utf-8".
-              let tmpStr = this.decodeStringContent(octetArray, charset);
-              let encoder = new TextEncoder("UTF-8");
-              content = new Blob([encoder.encode(tmpStr)], {type : mimeType});
+        if (mimeType) {
+          if (mimeType == "application/smil") {
+            // 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.
+            content = this.decodeStringContent(octetArray, charset);
+          } else if (mimeType.indexOf("text/") == 0 && charset != "utf-8") {
+            // If the content is a "text/plain" type, we have to make sure
+            // the encoding of the blob content should always be "utf-8".
+            let tmpStr = this.decodeStringContent(octetArray, charset);
+            let encoder = new TextEncoder("UTF-8");
+            content = new Blob([encoder.encode(tmpStr)], {type : mimeType});
 
-              // Make up the missing encoding info.
-              if (!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";
+            // Make up the missing encoding info.
+            if (!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 (!content) {
-            content = new Blob([octetArray], {type : mimeType});
-          }
+        if (!content) {
+          content = new Blob([octetArray], {type : mimeType});
         }
 
         parts[i] = {
           index: i,
           headers: headers,
           content: content,
         };
       } catch (e) {