aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEinar Egilsson2012-03-11 14:01:57 -0700
committerEinar Egilsson2012-03-11 14:01:57 -0700
commit211b9c04f45b30992b9c8d976a6ff594bbd291f3 (patch)
tree77370c4687472c27d036d70e5aac85d63d66b721
parent96397b66079d524f223911f882e3521396c4900c (diff)
parentae436464d221d3ba4535455f616ceb473e07e0cc (diff)
Merge pull request #1 from rampion/master
Adding URL escaping patch from rampion.
-rw-r--r--chrome/js/redirect.js20
-rw-r--r--chrome/js/redirector-ui.js2
-rw-r--r--chrome/js/redirector.js2
-rw-r--r--chrome/redirector.html6
4 files changed, 23 insertions, 7 deletions
diff --git a/chrome/js/redirect.js b/chrome/js/redirect.js
index 8b0b1d2..4a05ef8 100644
--- a/chrome/js/redirect.js
+++ b/chrome/js/redirect.js
@@ -2,8 +2,8 @@
var EXPORTED_SYMBOLS = ['Redirect'];
-function Redirect(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, disabled) {
- this._init(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, disabled);
+function Redirect(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, escapeMatches, disabled) {
+ this._init(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, escapeMatches, disabled);
}
//Static
@@ -36,6 +36,7 @@ Redirect.prototype = {
},
unescapeMatches : false,
+ escapeMatches : false,
disabled : false,
@@ -57,6 +58,7 @@ Redirect.prototype = {
redirectUrl : this.redirectUrl,
patternType : this.patternType,
unescapeMatches : this.unescapeMatches,
+ escapeMatches : this.escapeMatches,
disabled : !!this.disabled
};
},
@@ -75,6 +77,7 @@ Redirect.prototype = {
this.redirectUrl = other.redirectUrl;
this.patternType = other.patternType;
this.unescapeMatches = other.unescapeMatches;
+ this.escapeMatches = other.escapeMatches;
this.disabled = other.disabled;
},
@@ -85,6 +88,7 @@ Redirect.prototype = {
&& this.redirectUrl == redirect.redirectUrl
&& this.patternType == redirect.patternType
&& this.unescapeMatches == redirect.unescapeMatches
+ && this.escapeMatches == redirect.escapeMatches
;
},
@@ -164,13 +168,14 @@ Redirect.prototype = {
return new RegExp(this._preparePattern(pattern),"gi");
},
- _init : function(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, disabled) {
+ _init : function(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, escapeMatches, disabled) {
this.exampleUrl = exampleUrl || '';
this.includePattern = includePattern || '';
this.excludePattern = excludePattern || '';
this.redirectUrl = redirectUrl || '';
this.patternType = patternType || Redirect.WILDCARD;
this.unescapeMatches = (unescapeMatches === 'true' || unescapeMatches === true);
+ this.escapeMatches = (escapeMatches === 'true' || escapeMatches === true);
this.disabled = (disabled === 'true' || disabled === true);
},
@@ -182,6 +187,7 @@ Redirect.prototype = {
+ '\n\tRedirect url : ' + this.redirectUrl
+ '\n\tPattern type : ' + this.patternType
+ '\n\tUnescape matches : ' + this.unescapeMatches
+ + '\n\tEscape matches : ' + this.escapeMatches
+ '\n\tDisabled : ' + this.disabled
+ '\n}\n';
},
@@ -196,7 +202,11 @@ Redirect.prototype = {
}
var resultUrl = this.redirectUrl;
for (var i = 1; i < matches.length; i++) {
- resultUrl = resultUrl.replace(new RegExp('\\$' + i, 'gi'), this.unescapeMatches ? unescape(matches[i]) : matches[i]);
+ resultUrl = resultUrl.replace(new RegExp('\\$' + i, 'gi'),
+ this.unescapeMatches ? unescape(matches[i]) :
+ this.escapeMatches ? encodeURIComponent(matches[i]) :
+ matches[i]
+ );
}
this._rxInclude.lastIndex = 0;
return resultUrl;
@@ -210,4 +220,4 @@ Redirect.prototype = {
this._rxExclude.lastIndex = 0;
return shouldExclude;
}
-}; \ No newline at end of file
+};
diff --git a/chrome/js/redirector-ui.js b/chrome/js/redirector-ui.js
index 8deb20d..bd709cc 100644
--- a/chrome/js/redirector-ui.js
+++ b/chrome/js/redirector-ui.js
@@ -148,6 +148,7 @@ function bindRedirect(redirect) {
$('#redirect-to').val(redirect.redirectUrl);
$('#redirect-enabled').attr('checked', !redirect.disabled);
$('#unescape-matches').attr('checked', redirect.unescapeMatches);
+ $('#escape-matches').attr('checked', redirect.escapeMatches);
$('#regex-pattern').attr('checked', redirect.patternType == Redirect.REGEX);
$('#wildcard-pattern').attr('checked', redirect.patternType == Redirect.WILDCARD);
}
@@ -180,6 +181,7 @@ function controlsToRedirect(redirect) {
redirect.redirectUrl = $('#redirect-to').val();
redirect.disabled = !$('#redirect-enabled').attr('checked');
redirect.unescapeMatches = $('#unescape-matches').attr('checked');
+ redirect.escapeMatches = $('#escape-matches').attr('checked');
return true;
}
diff --git a/chrome/js/redirector.js b/chrome/js/redirector.js
index d2bcc51..5f4fa2a 100644
--- a/chrome/js/redirector.js
+++ b/chrome/js/redirector.js
@@ -345,4 +345,4 @@ Redirector = {
}
};
-Redirector.init(); \ No newline at end of file
+Redirector.init();
diff --git a/chrome/redirector.html b/chrome/redirector.html
index 6dcb39d..68300c1 100644
--- a/chrome/redirector.html
+++ b/chrome/redirector.html
@@ -67,6 +67,10 @@
<input type="checkbox" id="unescape-matches" />
</div>
<div>
+ <label>Escape matches</label>
+ <input type="checkbox" id="escape-matches" />
+ </div>
+ <div>
<label>Enabled</label>
<input type="checkbox" id="redirect-enabled" />
</div>
@@ -77,4 +81,4 @@
</div>
</div>
</body>
-</html> \ No newline at end of file
+</html>