Bug 948399 - [Messages] Subject. A subject containing special characters sent in a message is not received correctly. r=vicamo, a=1.3+
authorGene Lian <clian@mozilla.com>
Thu, 16 Jan 2014 16:32:07 +0800
changeset 175910 f9e38adda8ee3a74ed54366a35657a8c406fa155
parent 175909 7ed35166821a08444c5779e0531c06089d81192e
child 175911 72af78a81714f6ae121b871186ec66e5ca2a3377
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvicamo, 1
bugs948399
milestone28.0a2
Bug 948399 - [Messages] Subject. A subject containing special characters sent in a message is not received correctly. r=vicamo, a=1.3+
dom/mobilemessage/src/gonk/MmsPduHelper.jsm
dom/mobilemessage/src/gonk/WspPduHelper.jsm
--- a/dom/mobilemessage/src/gonk/MmsPduHelper.jsm
+++ b/dom/mobilemessage/src/gonk/MmsPduHelper.jsm
@@ -712,17 +712,27 @@ this.EncodedStringValue = {
    * @param data
    *        A wrapped object to store encoded raw data.
    * @param str
    *        A string.
    */
   encode: function encode(data, str) {
     let begin = data.offset;
     try {
-      WSP.TextString.encode(data, str);
+      // Quoted from OMA-TS-MMS-CONF-V1_3-20110913-A:
+      // Some of the MMS headers have been defined as "Encoded-string-value".
+      // The character set IANA MIBEnum value in these headers SHALL be
+      // encoded as Integer-value ([WAPWSP] section 8.4.2.3). The character
+      // set us-ascii (IANA MIBenum 3) SHALL always be accepted. If the
+      // character set is not specified (simple Text-string encoding) the
+      // character set SHALL be identified as us-ascii (lower half of ISO
+      // 8859-1 [ISO8859-1]). When the text string cannot be represented as
+      // us-ascii, the character set SHALL be encoded as utf-8 (IANA MIBenum
+      // 106) which has unique byte ordering.
+      WSP.TextString.encode(data, str, true);
     } catch (e) {
       data.offset = begin;
       this.encodeCharsetEncodedString(data, str);
     }
   },
 };
 
 /**
--- a/dom/mobilemessage/src/gonk/WspPduHelper.jsm
+++ b/dom/mobilemessage/src/gonk/WspPduHelper.jsm
@@ -378,26 +378,29 @@ this.Text = {
     return " ";
   },
 
   /**
    * @param data
    *        A wrapped object to store encoded raw data.
    * @param text
    *        String text of one character to be encoded.
+   * @param asciiOnly
+   *        A boolean to decide if it's only allowed to encode ASCII (0 ~ 127).
    *
    * @throws CodeError if a control character got.
    */
-  encode: function encode(data, text) {
+  encode: function encode(data, text, asciiOnly) {
     if (!text) {
       throw new CodeError("Text: empty string");
     }
 
     let code = text.charCodeAt(0);
-    if ((code < CTLS) || (code == DEL) || (code > 255)) {
+    if ((code < CTLS) || (code == DEL) || (code > 255) ||
+        (code >= 128 && asciiOnly)) {
       throw new CodeError("Text: invalid char code " + code);
     }
     Octet.encode(data, code);
   },
 };
 
 this.NullTerminatedTexts = {
   /**
@@ -420,21 +423,23 @@ this.NullTerminatedTexts = {
     }
   },
 
   /**
    * @param data
    *        A wrapped object to store encoded raw data.
    * @param str
    *        A String to be encoded.
+   * @param asciiOnly
+   *        A boolean to decide if it's only allowed to encode ASCII (0 ~ 127).
    */
-  encode: function encode(data, str) {
+  encode: function encode(data, str, asciiOnly) {
     if (str) {
       for (let i = 0; i < str.length; i++) {
-        Text.encode(data, str.charAt(i));
+        Text.encode(data, str.charAt(i), asciiOnly);
       }
     }
     Octet.encode(data, 0);
   },
 };
 
 /**
  * TOKEN = 1*<any CHAR except CTLs or separators>
@@ -585,29 +590,35 @@ this.TextString = {
     return NullTerminatedTexts.decode(data);
   },
 
   /**
    * @param data
    *        A wrapped object to store encoded raw data.
    * @param str
    *        A String to be encoded.
+   * @param asciiOnly
+   *        A boolean to decide if it's only allowed to encode ASCII (0 ~ 127).
    */
-  encode: function encode(data, str) {
+  encode: function encode(data, str, asciiOnly) {
     if (!str) {
       Octet.encode(data, 0);
       return;
     }
 
     let firstCharCode = str.charCodeAt(0);
     if (firstCharCode >= 128) {
+      if (asciiOnly) {
+        throw new CodeError("Text: invalid char code " + code);
+      }
+
       Octet.encode(data, 127);
     }
 
-    NullTerminatedTexts.encode(data, str);
+    NullTerminatedTexts.encode(data, str, asciiOnly);
   },
 };
 
 /**
  * Token-text = Token End-of-string
  *
  * @see WAP-230-WSP-20010705-a clause 8.4.2.1
  */