Bug 1108382 - Part 11: Do not use non-standard flag argument of String.prototype.replace in services/. r=rnewman

This commit is contained in:
Tooru Fujisawa 2015-03-01 09:51:33 +09:00
parent 4c8ea1ac1e
commit 4d59d774bf
3 changed files with 14 additions and 9 deletions

View File

@ -83,10 +83,10 @@ this.CommonUtils = {
* to true for historical reasons.
*/
encodeBase64URL: function encodeBase64URL(bytes, pad=true) {
let s = btoa(bytes).replace("+", "-", "g").replace("/", "_", "g");
let s = btoa(bytes).replace(/\+/g, "-").replace(/\//g, "_");
if (!pad) {
s = s.replace("=", "", "g");
return s.replace(/=+$/, "");
}
return s;

View File

@ -545,7 +545,7 @@ AbstractHealthReporter.prototype = Object.freeze({
// HealthReporter instances, we need to encode a unique identifier in
// the timer ID.
try {
let timerName = this._branch.replace(".", "-", "g") + "lastDailyCollection";
let timerName = this._branch.replace(/\./g, "-") + "lastDailyCollection";
let tm = Cc["@mozilla.org/updates/timer-manager;1"]
.getService(Ci.nsIUpdateTimerManager);
tm.registerTimer(timerName, this.collectMeasurements.bind(this),
@ -762,13 +762,18 @@ AbstractHealthReporter.prototype = Object.freeze({
// where UAppData is underneath the profile directory (or vice-versa) so we
// don't substitute incomplete strings.
// Return a /g regex that matches the provided string exactly.
function regexify(s) {
return new RegExp(s.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&"), "g");
}
function replace(uri, path, thing) {
// Try is because .spec can throw on invalid URI.
try {
recordMessage = recordMessage.replace(uri.spec, '<' + thing + 'URI>', 'g');
recordMessage = recordMessage.replace(regexify(uri.spec), "<" + thing + "URI>");
} catch (ex) { }
recordMessage = recordMessage.replace(path, '<' + thing + 'Path>', 'g');
recordMessage = recordMessage.replace(regexify(path), "<" + thing + "Path>");
}
if (appData.path.contains(profile.path)) {

View File

@ -253,14 +253,14 @@ this.Utils = {
*/
base32ToFriendly: function base32ToFriendly(input) {
return input.toLowerCase()
.replace("l", '8', "g")
.replace("o", '9', "g");
.replace(/l/g, '8')
.replace(/o/g, '9');
},
base32FromFriendly: function base32FromFriendly(input) {
return input.toUpperCase()
.replace("8", 'L', "g")
.replace("9", 'O', "g");
.replace(/8/g, 'L')
.replace(/9/g, 'O');
},
/**