Bug 1225983 - Stop modifying String prototype in calExtract.jsm. r/a=philipp
authorMerike Sell <merike.sell@eesti.ee>
Sun, 20 Dec 2015 05:35:00 +0100
changeset 26633 e10f9b929a4045d355cfcf0e241721b17e269e0e
parent 26632 1c4e397973ecceba2fce8ddc24f996ac1e7a385b
child 26634 077395cf8fa3ad79a5ed030d476841c7dc216eec
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)
bugs1225983
Bug 1225983 - Stop modifying String prototype in calExtract.jsm. r/a=philipp
calendar/base/modules/calExtract.jsm
--- a/calendar/base/modules/calExtract.jsm
+++ b/calendar/base/modules/calExtract.jsm
@@ -442,17 +442,17 @@ Extractor.prototype = {
 
             while ((res = re.exec(this.email)) != null) {
                 if (!this.limitNums(res, this.email) && !this.limitChars(res, this.email)) {
                     let day = this.parseNumber(res[positions[1]], this.numbers);
                     let month = res[positions[2]];
 
                     if (this.isValidDay(day)) {
                         for (let i = 0; i < 12; i++) {
-                            let ms = this.months[i].unescape().split("|");
+                            let ms = this.unescape(this.months[i]).split("|");
                             if (ms.includes(month.toLowerCase())) {
                                 let date = {year: this.now.getFullYear(), month: i + 1, day: day};
                                 if (this.isPastDate(date, this.now)) {
                                     // find next such date
                                     let item = new Date(this.now.getTime());
                                     while (true) {
                                         item.setDate(item.getDate() + 1);
                                         if (item.getMonth() == date.month - 1 &&
@@ -1105,17 +1105,17 @@ Extractor.prototype = {
         }
         return positions;
     },
 
     cleanPatterns: function cleanPatterns(pattern) {
         // remove whitespace around | if present
         let value = pattern.replace(/\s*\|\s*/g, "|");
         // allow matching for patterns with missing or excessive whitespace
-        return value.sanitize().replace(/\s+/g, "\\s*");
+        return this.sanitize(value).replace(/\s+/g, "\\s*");
     },
 
     checkForFaultyPatterns: function checkForFaultyPatterns(pattern, name) {
         if (/^\s*\|/.exec(pattern) || /\|\s*$/.exec(pattern) || /\|\s*\|/.exec(pattern)) {
             dump("[calExtract] Faulty extraction pattern " +
                  pattern + " for " + name + "\n");
             Components.utils.reportError("[calExtract] Faulty extraction pattern " +
                                          pattern + " for " + name);
@@ -1267,19 +1267,18 @@ Extractor.prototype = {
         let guess = {year: year, month: month, day: day, hour: hour, minute: minute,
                      start: start, end: end, str: str, relation: relation,
                      pattern: pattern, ambiguous: ambiguous};
         // past dates are kept for containment checks
         if (this.isPastDate(guess, this.now)) {
             guess.relation = "notadatetime";
         }
         this.collected.push(guess);
+    },
+
+    sanitize: function(str) {
+        return str.replace(/[-[\]{}()*+?.,\\^$]/g, "\\$&");
+    },
+
+    unescape: function(str) {
+        return str.replace(/\\([\.])/g, "$1");
     }
 };
-
-String.prototype.sanitize = function() {
-    return this.replace(/[-[\]{}()*+?.,\\^$]/g, "\\$&");
-}
-
-String.prototype.unescape = function() {
-    let res = this.replace(/\\([\.])/g, "$1");
-    return res;
-}