Backout bug 849797 - resPathComponents[endBasePos] is undefined. r=mmecca,a=philipp SEAMONKEY_2_17b3_BUILD1 SEAMONKEY_2_17b3_RELEASE
authorPhilipp Kewisch <mozilla@kewis.ch>
Wed, 20 Mar 2013 12:32:36 +0100
changeset 14683 02c412fc57f14f3d191ea698a835221eb4375c11
parent 14682 58816ab28194ed25bf458c704c5833b094cac151
child 14684 87f86bc0810e984e3fc527a8b7f47d7b69184b5a
child 14686 2b558863434c5a55744e9cd660a245a5899218aa
push idunknown
push userunknown
push dateunknown
reviewersmmecca, philipp
bugs849797
Backout bug 849797 - resPathComponents[endBasePos] is undefined. r=mmecca,a=philipp
calendar/providers/caldav/calDavCalendar.js
--- a/calendar/providers/caldav/calDavCalendar.js
+++ b/calendar/providers/caldav/calDavCalendar.js
@@ -978,18 +978,17 @@ calDavCalendar.prototype = {
      * @param aListener Listener
      */
     addTargetCalendarItem : function caldav_addTargetCalendarItem(path,calData,aUri, etag, aListener) {
         let parser = Components.classes["@mozilla.org/calendar/ics-parser;1"]
                                .createInstance(Components.interfaces.calIIcsParser);
         // aUri.path may contain double slashes whereas path does not
         // this confuses our counting, so remove multiple successive slashes
         let strippedUriPath = aUri.path.replace(/\/{2,}/g, "/");
-        let uriPathComponents = strippedUriPath.split("/");
-        let uriPathComponentLength = uriPathComponents.length;
+        let uriPathComponentLength = strippedUriPath.split("/").length;
         try {
             parser.parseString(calData);
         } catch (e) {
             // Warn and continue.
             // TODO As soon as we have activity manager integration,
             // this should be replace with logic to notify that a
             // certain event failed.
             cal.WARN("Failed to parse item: " + calData + "\n\nException:" + e);
@@ -1020,45 +1019,19 @@ calDavCalendar.prototype = {
             cal.WARN("REPLY method but calendar does not support scheduling");
             return;
         }
 
         // Strip of the same number of components as the request
         // uri's path has. This way we make sure to handle servers
         // that pass paths like /dav/user/Calendar while
         // the request uri is like /dav/user@example.org/Calendar.
-        // But we also need to handle the case where the server passes back
-        // a valid path that just has additional redundant components,
-        // like /dav/davical.php/user@example/Calendar
         let resPathComponents = path.split("/");
-        let isEitherSubstring = function(s1, s2) {
-            return (s1.length < s2.length ? s2.indexOf(s1) : s1.indexOf(s2)) >= 0;
-        }
-        while (uriPathComponentLength > 0 && !uriPathComponents[uriPathComponentLength - 1].length) {
-           uriPathComponentLength--;
-        }
-        let lastComp = "";
-        if (uriPathComponentLength > 0) {
-           lastComp = uriPathComponents[uriPathComponentLength - 1].toLowerCase();
-        }
-        let endBasePos = resPathComponents.length - 2;
-        while (endBasePos >= 0 && !isEitherSubstring(lastComp, resPathComponents[endBasePos].toLowerCase())) {
-            endBasePos++;
-        }
-        if (endBasePos < 0) {
-            endBasePos = resPathComonents.length - 2;
-        }
-
-        // If endBasePos is negative, no obvious reference to the end of the
-        // base uri was found, so just keep the tail.
-        let splicePos = (endBasePos < 0 ? rePathComponents.length - 2 : endBasePos + 1);
-        resPathComponents.splice(0, splicePos);
+        resPathComponents.splice(0, uriPathComponentLength - 1);
         let locationPath = resPathComponents.join("/");
-        cal.ERROR("LOCATION PATH IS NOW " + locationPath);
-
         let isInboxItem = this.isInbox(aUri.spec);
 
         if (this.mHrefIndex[path] &&
             !this.mItemInfoCache[item.id]) {
             // If we get here it means a meeting has kept the same filename
             // but changed its uid, which can happen server side.
             // Delete the meeting before re-adding it
             this.deleteTargetCalendarItem(path);