Bug 1108382 - Part 2: Do not use non-standard flag argument of String.prototype.match/replace in browser/components/translation/. r=felipe
authorTooru Fujisawa <arai_a@mac.com>
Sun, 01 Mar 2015 09:51:33 +0900
changeset 246736 a1ece54a978e7875fa176bca1bf80148f368cd6f
parent 246735 fe24d1b2b608994846b1cfd3bc464ff07413c7fc
child 246737 d3df8a46f7213256a8333d0e44cf9033a60769ce
push id879
push usercliu@mozilla.com
push dateTue, 03 Mar 2015 03:02:53 +0000
reviewersfelipe
bugs1108382
milestone39.0a1
Bug 1108382 - Part 2: Do not use non-standard flag argument of String.prototype.match/replace in browser/components/translation/. r=felipe
browser/components/translation/BingTranslator.jsm
--- a/browser/components/translation/BingTranslator.jsm
+++ b/browser/components/translation/BingTranslator.jsm
@@ -202,17 +202,17 @@ this.BingTranslator.prototype = {
     for (let i = 0; i < len; i++) {
       try {
         let result = results[i].firstChild.nodeValue;
         let root = bingRequest.translationData[i][0];
 
         if (root.isSimpleRoot) {
           // Workaround for Bing's service problem in which "&" chars in
           // plain-text TranslationItems are double-escaped.
-          result = result.replace("&amp;", "&", "g");
+          result = result.replace(/&amp;/g, "&");
         }
 
         root.parseResult(result);
       } catch (e) { error = true; }
     }
 
     return !error;
   },
@@ -417,21 +417,21 @@ let BingTokenManager = {
   }
 };
 
 /**
  * Escape a string to be valid XML content.
  */
 function escapeXML(aStr) {
   return aStr.toString()
-             .replace("&", "&amp;", "g")
-             .replace('"', "&quot;", "g")
-             .replace("'", "&apos;", "g")
-             .replace("<", "&lt;", "g")
-             .replace(">", "&gt;", "g");
+             .replace(/&/g, "&amp;")
+             .replace(/\"/g, "&quot;")
+             .replace(/\'/g, "&apos;")
+             .replace(/</g, "&lt;")
+             .replace(/>/g, "&gt;");
 }
 
 /**
  * Fetch an auth token (clientID or client secret), which may be overridden by
  * a pref if it's set.
  */
 function getUrlParam(paramValue, prefName, encode = true) {
   if (Services.prefs.getPrefType(prefName))