Bug 1289939 - trim display name properly. r=aceman a=jorgk DONTBUILD BETA_BASE_20160801
authorJorg K <mozilla@jorgk.com>
Sun, 31 Jul 2016 09:42:59 +0200
changeset 25164 bbc8353aec50fbc6c05fa2d11306075cf9ddefc6
parent 25163 7ff0f2fce8e755677eefd7291231203680f1df58
child 25165 4fda5765e00d740667437d57365ff641347cf3b8
push id1688
push userclokep@gmail.com
push dateMon, 01 Aug 2016 16:45:40 +0000
treeherdercomm-beta@9abd7cedb2af [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman, jorgk
bugs1289939
Bug 1289939 - trim display name properly. r=aceman a=jorgk DONTBUILD
mailnews/mime/src/mimeJSComponents.js
mailnews/mime/test/unit/test_nsIMsgHeaderParser4.js
--- a/mailnews/mime/src/mimeJSComponents.js
+++ b/mailnews/mime/src/mimeJSComponents.js
@@ -368,20 +368,18 @@ MimeAddressParser.prototype = {
     return output;
   },
 
   /// Construct a single email address from a name <local@domain> token.
   _makeSingleAddress: function (aDisplayName) {
     if (aDisplayName.includes('<')) {
       let lbracket = aDisplayName.lastIndexOf('<');
       let rbracket = aDisplayName.lastIndexOf('>');
-      // If there are multiple spaces between the display name and the bracket,
-      // strip off only a single space.
       return this.makeMailboxObject(
-        lbracket == 0 ? '' : aDisplayName.slice(0, lbracket - 1),
+        lbracket == 0 ? '' : aDisplayName.slice(0, lbracket).trim(),
         aDisplayName.slice(lbracket + 1, rbracket));
     } else {
       return this.makeMailboxObject('', aDisplayName);
     }
   },
 
   // What follows is the deprecated API that will be removed shortly.
 
--- a/mailnews/mime/test/unit/test_nsIMsgHeaderParser4.js
+++ b/mailnews/mime/test/unit/test_nsIMsgHeaderParser4.js
@@ -12,21 +12,34 @@ function run_test() {
       addresses: [] },
     { displayString: "test@foo.invalid",
       addresses: [["", "test@foo.invalid"]] },
     { displayString: "test@foo.invalid, test2@foo.invalid",
       addresses: [["", "test@foo.invalid"],
                   ["", "test2@foo.invalid"]] },
     { displayString: "John Doe <test@foo.invalid>",
       addresses: [["John Doe", "test@foo.invalid"]] },
+    // Trim spaces.
+    { displayString: "  John Doe  <test@foo.invalid>",
+      addresses: [["John Doe", "test@foo.invalid"]] },
+    // No space before the email address.
+    { displayString: " John Doe<test@foo.invalid>",
+      addresses: [["John Doe", "test@foo.invalid"]] },
+    // Additional text after the email address to be ignored.
+    { displayString: " John Doe<test@foo.invalid> Junior",
+      addresses: [["John Doe", "test@foo.invalid"]] },
     { displayString: "Doe, John <test@foo.invalid>",
       addresses: [["Doe, John", "test@foo.invalid"]] },
     { displayString: "Doe, John <test@foo.invalid>, Bond, James <test2@foo.invalid>",
       addresses: [["Doe, John", "test@foo.invalid"],
                   ["Bond, James", "test2@foo.invalid"]] },
+    // Additional text after the email address to be ignored, multiple addresses.
+    { displayString: "Doe, John <test@foo.invalid>Junior, Bond, James <test2@foo.invalid>007",
+      addresses: [["Doe, John", "test@foo.invalid"],
+                  ["Bond, James", "test2@foo.invalid"]] },
   ];
 
   // Test -  strings
 
   for (let i = 0; i < checks.length; ++i) {
     dump("Test " + i + "\n");
     let addrs = MailServices.headerParser.makeFromDisplayAddress(checks[i].displayString, {});
     let checkaddrs = checks[i].addresses;