aboutsummaryrefslogtreecommitdiff
path: root/components/redirector.js
diff options
context:
space:
mode:
authorEinar Egilsson2009-09-14 14:06:50 +0000
committerEinar Egilsson2009-09-14 14:06:50 +0000
commit10e637b427e5cdd9b5b6660469391cac525da637 (patch)
treeda323d35e5f6c0eea7112e7dc87103205f89d59c /components/redirector.js
parent8f42f80d0d6de5eb904843b4fbb9a2e0968f7046 (diff)
Unescape matches option + some unit tests
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@245 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'components/redirector.js')
-rw-r--r--components/redirector.js24
1 files changed, 14 insertions, 10 deletions
diff --git a/components/redirector.js b/components/redirector.js
index 09ef35e..4e44c11 100644
--- a/components/redirector.js
+++ b/components/redirector.js
@@ -50,7 +50,8 @@ function RedirectorPolicy() {
pattern : arr[1],
redirectUrl : arr[2],
patternType : arr[3],
- excludePattern : arr[4]
+ excludePattern : arr[4],
+ unescapeMatches : !!arr[5] //This might be undefined for those upgrading from 1.7.1 but that's ok
});
}
}
@@ -117,6 +118,10 @@ RedirectorPolicy.prototype = {
this.prefBranch.setBoolPref('enabled', val);
},
+ reload : function() {
+ //TODO: Reload implementation
+ },
+
addRedirect : function(redirect) {
this.list.push(redirect);
this.save();
@@ -132,7 +137,7 @@ RedirectorPolicy.prototype = {
, tempList = [];
for each (r in this.list) {
- tempList.push([r.exampleUrl, r.pattern, r.redirectUrl, r.patternType, r.excludePattern].join(',,,'));
+ tempList.push([r.exampleUrl, r.pattern, r.redirectUrl, r.patternType, r.excludePattern, r.unescapeMatches].join(',,,'));
}
this.prefBranch.setCharPref('redirects', tempList.join(':::'));
},
@@ -141,7 +146,7 @@ RedirectorPolicy.prototype = {
return this.prefBranch.getBoolPref(name);
},
- regexMatch : function(pattern, text, redirectUrl) {
+ regexMatch : function(pattern, text, redirectUrl, unescapeMatches) {
if (!pattern) {
return null;
@@ -160,7 +165,7 @@ RedirectorPolicy.prototype = {
if (match) {
for (var i = 1; i < match.length; i++) {
rxrepl = new RegExp('\\$' + i, 'gi');
- redirectUrl = redirectUrl.replace(rxrepl, match[i]);
+ redirectUrl = redirectUrl.replace(rxrepl, unescapeMatches ? unescape(match[i]) : match[i]);
}
return redirectUrl;
}
@@ -182,13 +187,13 @@ RedirectorPolicy.prototype = {
this.debug(url + ' matches exclude pattern ' + redirect.excludePattern);
return null;
}
- return this.wildcardMatch(redirect.pattern, url, redirect.redirectUrl);
+ return this.wildcardMatch(redirect.pattern, url, redirect.redirectUrl, redirect.unescapeMatches);
} else if (redirect.patternType == kRedirectorRegex) {
if (this.regexMatch(redirect.excludePattern, url, 'whatever')) {
this.debug(url + ' matches exclude pattern ' + redirect.excludePattern);
return null;
}
- return this.regexMatch(redirect.pattern, url, redirect.redirectUrl);
+ return this.regexMatch(redirect.pattern, url, redirect.redirectUrl, redirect.unescapeMatches);
}
return null;
},
@@ -206,7 +211,7 @@ RedirectorPolicy.prototype = {
return uri.resolve(relativeUrl);
},
- wildcardMatch : function(pattern, text, redirectUrl) {
+ wildcardMatch : function(pattern, text, redirectUrl, unescapeMatches) {
var parts
, part
, i
@@ -239,15 +244,14 @@ RedirectorPolicy.prototype = {
if (i == parts.length -1 && i != "" && text.substr(text.length - part.length) != part) {
return null;
-
}
if (i == 0) {
//Do nothing, part will be added on next run
} else if (i == parts.length-1 && parts[i] == '') {
- stars.push(text);
+ stars.push(unescapeMatches ? unescape(text) : text);
} else {
- stars.push(text.substr(0, pos));
+ stars.push(unescapeMatches ? unescape(text.substr(0, pos)) : text.substr(0, pos));
}
text = text.substr(pos + part.length);