Bug 773592: suppor MMS headers with multiple values, r=philikon
authorVicamo Yang <vyang@mozilla.com>
Fri, 20 Jul 2012 14:40:01 +0800
changeset 99889 126a1ebf55e640b2396960e679df4b028f896ac8
parent 99888 56b8e5d8c42f54631f3348085ea3f4e6a65e6ad2
child 99890 ecb9536114625eb610b6506dc13e33362acfc624
push id23151
push useremorley@mozilla.com
push dateFri, 20 Jul 2012 13:33:35 +0000
treeherdermozilla-central@3337f0685b75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilikon
bugs773592
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 773592: suppor MMS headers with multiple values, r=philikon
dom/mms/src/ril/MmsPduHelper.jsm
dom/mms/tests/test_mms_pdu_helper.js
--- a/dom/mms/src/ril/MmsPduHelper.jsm
+++ b/dom/mms/src/ril/MmsPduHelper.jsm
@@ -967,17 +967,24 @@ let PduHelper = {
     let header;
     while (data.offset < data.array.length) {
       // There is no `header length` information in MMS PDU. If we just got
       // something wrong in parsing header fields, we might not be able to
       // determine the correct header-content boundary.
       header = HeaderField.decode(data, headers);
 
       if (header) {
-        headers[header.name] = header.value;
+        let orig = headers[header.name];
+        if (Array.isArray(orig)) {
+          headers[header.name].push(header.value);
+        } else if (orig) {
+          headers[header.name] = [orig, header.value];
+        } else {
+          headers[header.name] = header.value;
+        }
         if (header.name == "content-type") {
           // `... if the PDU contains a message body the Content Type MUST be
           // the last header field, followed by message body.` See
           // OMA-TS-MMS_ENC-V1_3-20110913-A section 7.
           break;
         }
       }
     }
--- a/dom/mms/tests/test_mms_pdu_helper.js
+++ b/dom/mms/tests/test_mms_pdu_helper.js
@@ -545,8 +545,51 @@ add_test(function test_StatusValue_encod
     } else {
       wsp_encode_test(MMS.StatusValue, i, null, "CodeError");
     }
   }
 
   run_next_test();
 });
 
+//
+// Test target: PduHelper
+//
+
+//// PduHelper.parseHeaders ////
+
+add_test(function test_PduHelper_parseHeaders() {
+  function parse(input, expect, exception) {
+    let data = {array: input, offset: 0};
+    do_check_throws(wsp_test_func.bind(null, MMS.PduHelper.parseHeaders, data, expect),
+                    exception);
+  }
+
+  // Parse ends with Content-Type
+  let expect = {};
+  expect["x-mms-mms-version"] = MMS_VERSION;
+  expect["content-type"] = {
+    media: "application/vnd.wap.multipart.related",
+    params: null,
+  };
+  parse([0x80 | 0x0D, 0x80 | MMS_VERSION,   // X-Mms-Mms-Version: 1.3
+         0x80 | 0x04, 0x80 | 0x33,          // Content-Type: application/vnd.wap.multipart.related
+	 0x80 | 0x0C, MMS_PDU_TYPE_SEND_REQ // X-Mms-Message-Type: M-Send.req
+        ], expect);
+
+  // Parse header fields with multiple entries
+  expect = {
+    to: [
+      { address: "+123", type: "PLMN" },
+      { address: "+456", type: "num" },
+    ],
+  };
+  expect["content-type"] = {
+    media: "application/vnd.wap.multipart.related",
+    params: null,
+  };
+  parse(Array.concat([0x80 | 0x17]).concat(strToCharCodeArray("+123/TYPE=PLMN"))
+             .concat([0x80 | 0x17]).concat(strToCharCodeArray("+456"))
+             .concat([0x80 | 0x04, 0x80 | 0x33]),
+        expect);
+
+  run_next_test();
+});