Bug 1209399 - Attendees with comma in name do not work anymore;r=philipp
authorMakeMyDay <makemyday@gmx-topmail.de>
Mon, 16 Nov 2015 12:48:46 +0100
changeset 26525 2e74f8605f33486f2914d76688b18bc04c1e1d84
parent 26524 0257a4aa8b815cff7412bfe572520d95ba7daa1c
child 26526 aa25d5d0211c0111d8cc39b13e60d1446c2d87a2
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs1209399
Bug 1209399 - Attendees with comma in name do not work anymore;r=philipp
calendar/base/content/dialogs/calendar-event-dialog-attendees.xml
calendar/base/src/calItemBase.js
calendar/test/unit/test_bug1209399.js
calendar/test/unit/xpcshell-shared.ini
--- a/calendar/base/content/dialogs/calendar-event-dialog-attendees.xml
+++ b/calendar/base/content/dialogs/calendar-event-dialog-attendees.xml
@@ -399,20 +399,18 @@
                   let parsedInput = MailServices.headerParser.makeFromDisplayAddress(inputField.value);
                   let j = 0;
                   let addAttendee = function(aAddress) {
                       if (j > 0) {
                           attendee = attendee.clone();
                       }
                       attendee.id = cal.prependMailTo(aAddress.email);
                       if (aAddress.name.length > 0) {
-                          if (aAddress.name.startsWith('"') && aAddress.name.endsWith('"')) {
-                              aAddress.name.slice(1, -1);
-                          }
-                          attendee.commonName = aAddress.name;
+                          // we remove any double quotes within CN due to bug 1209399
+                          attendee.commonName = aAddress.name.replace(/(?:[\\]"|")/, "");
                       }
                       attendees.push(attendee);
                       j++;
                   };
                   parsedInput.forEach(addAttendee);
               }
           }
 
--- a/calendar/base/src/calItemBase.js
+++ b/calendar/base/src/calItemBase.js
@@ -564,16 +564,24 @@ calItemBase.prototype = {
             if (exists.participationStatus == "NEEDS-ACTION" ||
                 attendee.participationStatus == "DECLINED") {
                 this.removeAttendee(exists);
             } else {
                 attendee = null;
             }
         }
         if (attendee) {
+            if (attendee.commonName) {
+                // migration code for bug 1209399 to remove leading/training double quotes in
+                attendee.commonName = attendee.commonName
+                                              .replace(/^["]*([^"]*)["]*$/, "$1");
+                if (attendee.commonName.length == 0) {
+                    attendee.commonName = null;
+                }
+            }
             this.modify();
             this.mAttendees = this.getAttendees({});
             this.mAttendees.push(attendee);
         }
     },
 
     // void getAttachments(out PRUint32 count,
     //                     [array,size_is(count),retval] out calIAttachment attachments);
new file mode 100644
--- /dev/null
+++ b/calendar/test/unit/test_bug1209399.js
@@ -0,0 +1,99 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+Components.utils.import("resource://calendar/modules/calUtils.jsm");
+
+function run_test() {
+    // Test handling for multiple double quotes leading/trailing to attendee CN for bug 1209399
+    test_newAttendee();
+    test_fromICS();
+}
+
+function test_newAttendee() {
+    let data = [{
+        input: { cn: null, id: 'mailto:user1@example.net' },
+        expected: { cn: null }
+    }, {
+        input: { cn: 'Test2', id: 'mailto:user2@example.net' },
+        expected: { cn: 'Test2' }
+    }, {
+        input: { cn: '"Test3"', id: 'mailto:user3@example.net' },
+        expected: { cn: 'Test3' }
+    }, {
+        input: { cn: '""Test4""', id: 'mailto:user4@example.net' },
+        expected: { cn: 'Test4' }
+    }, {
+        input: { cn: '""Test5"', id: 'mailto:user5@example.net' },
+        expected: { cn: 'Test5' }
+    }, {
+        input: { cn: '"Test6""', id: 'mailto:user6@example.net' },
+        expected: { cn: 'Test6' }
+    }, {
+        input: { cn: '', id: 'mailto:user7@example.net' },
+        expected: { cn: '' }
+    }, {
+        input: { cn: '""', id: 'mailto:user8@example.net' },
+        expected: { cn: null }
+    }, {
+        input: { cn: '""""', id: 'mailto:user9@example.net' },
+        expected: { cn: null }
+    }];
+
+    let i = 0;
+    let event = cal.createEvent();
+    for (let test of data) {
+        i++;
+        let attendee = cal.createAttendee();
+        attendee.id = test.input.id;
+        attendee.commonName = test.input.cn;
+
+        event.addAttendee(attendee);
+        let readAttendee = event.getAttendeeById(test.input.id);
+        equal(readAttendee.commonName, test.expected.cn,
+              "Test #" + i + " for cn matching of " + test.input.id);
+    }
+}
+
+function test_fromICS() {
+    let ics = [
+        'BEGIN:VCALENDAR',
+        'PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN',
+        'VERSION:2.0',
+        'BEGIN:VEVENT',
+        'UID:a84c74d1-cfc6-4ddf-9d60-9e4afd8238cf',
+        'SUMMARY:New Event',
+        'DTSTART:20150729T103000Z',
+        'DTEND:20150729T113000Z',
+        'ORGANIZER;RSVP=TRUE;CN=Tester1;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:user1@example.net',
+
+        'ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;CN=Test2;ROLE=REQ-PARTICIPANT:mailto:user2@example.net',
+        'ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;CN="Test3";ROLE=REQ-PARTICIPANT:mailto:user3@example.net',
+        'ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;CN=""Test4"";ROLE=REQ-PARTICIPANT:mailto:user4@example.net',
+        'ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;CN=;ROLE=REQ-PARTICIPANT:mailto:user5@example.net',
+        'ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:mailto:user6@example.net',
+        'ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;CN="";ROLE=REQ-PARTICIPANT:mailto:user7@example.net',
+        'ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;CN="""";ROLE=REQ-PARTICIPANT:mailto:user8@example.net',
+
+        'END:VEVENT',
+        'END:VCALENDAR'
+    ].join("\n");
+
+    let expected = [
+        { id: 'mailto:user2@example.net', cn: 'Test2' },
+        { id: 'mailto:user3@example.net', cn: 'Test3' },
+        { id: 'mailto:user4@example.net', cn: '' },
+        { id: 'mailto:user5@example.net', cn: '' },
+        { id: 'mailto:user6@example.net', cn: null },
+        { id: 'mailto:user7@example.net', cn: '' },
+        { id: 'mailto:user8@example.net', cn: '' }
+    ];
+    let event = createEventFromIcalString(ics);
+    let attendees = event.getAttendees({});
+
+    equal(event.getAttendees({}).length, expected.length, "Check test consistency");
+    for (let exp of expected) {
+        let attendee = event.getAttendeeById(exp.id);
+        equal(attendee.commonName, exp.cn, "Test for cn matching of " + exp.id);
+    }
+}
--- a/calendar/test/unit/xpcshell-shared.ini
+++ b/calendar/test/unit/xpcshell-shared.ini
@@ -1,14 +1,15 @@
 [test_alarm.js]
 [test_alarmservice.js]
 [test_attachment.js]
 [test_attendee.js]
 [test_bug1199942.js]
 [test_bug1204255.js]
+[test_bug1209399.js]
 [test_bug272411.js]
 [test_bug343792.js]
 [test_bug350845.js]
 [test_bug356207.js]
 [test_bug485571.js]
 [test_bug486186.js]
 [test_bug494140.js]
 [test_bug523860.js]