aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEinar Egilsson2009-10-19 09:56:04 +0000
committerEinar Egilsson2009-10-19 09:56:04 +0000
commit7b4c3a2cdbc0f5ac9d237f91164ee8fea8210095 (patch)
tree4c7f8e7b87b08bd6a0e219a6786cbda91b79e6c9
parent0973b58a596cce626e9ace2752d390fbc11a1067 (diff)
Check for loop redirects implemented
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@280 119bf307-c92d-0410-89bd-8f53e6181181
-rw-r--r--build.bat2
-rw-r--r--chrome/content/code/redirect.js5
-rw-r--r--chrome/content/code/redirector.prototype.js21
-rw-r--r--chrome/locale/en-US/redirector.properties4
4 files changed, 25 insertions, 7 deletions
diff --git a/build.bat b/build.bat
deleted file mode 100644
index efbdb4f..0000000
--- a/build.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-REM $Id$
-mozbuild.py redirector.xpi \ No newline at end of file
diff --git a/chrome/content/code/redirect.js b/chrome/content/code/redirect.js
index 02e975d..7016715 100644
--- a/chrome/content/code/redirect.js
+++ b/chrome/content/code/redirect.js
@@ -163,11 +163,14 @@ Redirect.prototype = {
for (var i = 1; i < matches.length; i++) {
resultUrl = resultUrl.replace(new RegExp('\\$' + i, 'gi'), this.unescapeMatches ? unescape(matches[i]) : matches[i]);
}
+ this._rxInclude.lastIndex = 0;
return resultUrl;
},
_excludeMatch : function(url) {
- return !!(this._rxExclude && this._rxExclude.exec(url));
+ var shouldExclude = !!(this._rxExclude && this._rxExclude.exec(url));
+ this._rxExclude.lastIndex = 0;
+ return shouldExclude;
},
clone : function() {
diff --git a/chrome/content/code/redirector.prototype.js b/chrome/content/code/redirector.prototype.js
index 9135e50..991c289 100644
--- a/chrome/content/code/redirector.prototype.js
+++ b/chrome/content/code/redirector.prototype.js
@@ -97,7 +97,6 @@ Redirector.prototype = {
//Get the redirect url for the given url. This will not check if we are enabled, and
//not do any verification on the url, just assume that it is a good string url that is for http/s
getRedirectUrl : function(url) {
- //This is also done in getRedirectUrl, but we want to exit as quickly as possible for performance
this.debug("Checking " + url);
for each (var redirect in this.list) {
@@ -108,8 +107,20 @@ Redirector.prototype = {
this.debug(url + ' matched pattern ' + redirect.includePattern + ' but the redirect is disabled');
} else if (result.isMatch) {
redirectUrl = this.makeAbsoluteUrl(url, result.redirectTo);
- this.debug('Redirecting ' + url + ' to ' + redirectUrl);
- return redirectUrl;
+
+ //check for loops...
+ result = redirect.getMatch(redirectUrl);
+ if (result.isMatch) {
+ var title = this.getString('invalidRedirectTitle');
+ var msg = this.getFormattedString('invalidRedirectText', [redirect.includePattern, url, redirectUrl]);
+ this.debug(msg);
+ redirect.disabled = true;
+ this.save();
+ this.msgBox(title, msg);
+ } else {
+ this.debug('Redirecting ' + url + ' to ' + redirectUrl);
+ return redirectUrl;
+ }
}
}
return null;
@@ -249,6 +260,10 @@ Redirector.prototype = {
return this.strings.GetStringFromName(name);
},
+ getFormattedString : function(name, params) {
+ return this.strings.formatStringFromName(name, params, params.length);
+ },
+
msgBox : function(title, text) {
Cc["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService)
diff --git a/chrome/locale/en-US/redirector.properties b/chrome/locale/en-US/redirector.properties
index 304f58f..4f16de5 100644
--- a/chrome/locale/en-US/redirector.properties
+++ b/chrome/locale/en-US/redirector.properties
@@ -24,4 +24,6 @@ existedMessageSingular=%S redirect was identical to an existing redirect and was
allExistedMessage=All %S redirects in the file were identical to existing redirects, no redirects were imported.
allExistedMessageSingular=The single redirect in the file was identical to an existing redirect and was therefore not imported.
importedNone=There were no usable redirects in the given file, no redirects were imported.
-importResult=Import results \ No newline at end of file
+importResult=Import results
+invalidRedirectTitle=Redirector Add-on: Invalid Redirect detected
+invalidRedirectText=The pattern "%S" redirected the url %S to %S which also matches the pattern. This will cause an endless loop and so the redirect has been disabled to prevent this from happening. You should edit this redirect to fix it. \ No newline at end of file