aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEinar Egilsson <einar@einaregilsson.com>2016-01-15 22:41:12 +0000
committerEinar Egilsson <einar@einaregilsson.com>2016-01-15 22:41:12 +0000
commit87722144b6ac563dc1fed4f5a647e74eb121b4ae (patch)
tree280529d3dbca2c3f0c92d9e447c4dd6c715492ce
parenta6256b5e4371ab04e318c797d1121528e8f23c3a (diff)
Add Base64 Decode feature. Simplify UI
-rw-r--r--css/redirector.css4
-rw-r--r--js/redirect.js27
-rw-r--r--redirector.html19
3 files changed, 34 insertions, 16 deletions
diff --git a/css/redirector.css b/css/redirector.css
index 97b877c..9417eb1 100644
--- a/css/redirector.css
+++ b/css/redirector.css
@@ -416,6 +416,10 @@ a.disabled:hover {
margin-top:2px;
}
+.advanced div .input-cell select {
+ margin-top:4px;
+ width:160px;
+}
a[ng-click] {
cursor:pointer;
diff --git a/js/redirect.js b/js/redirect.js
index c9036e1..718d5f2 100644
--- a/js/redirect.js
+++ b/js/redirect.js
@@ -23,6 +23,7 @@ Redirect.requestTypes = {
other : "Other"
};
+
Redirect.prototype = {
//attributes
@@ -34,8 +35,7 @@ Redirect.prototype = {
excludePattern : '',
redirectUrl : '',
patternType : '',
- unescapeMatches : false,
- escapeMatches : false,
+ processMatches : 'noProcessing',
disabled : false,
compile : function() {
@@ -58,8 +58,7 @@ Redirect.prototype = {
&& this.excludePattern == redirect.excludePattern
&& this.redirectUrl == redirect.redirectUrl
&& this.patternType == redirect.patternType
- && this.unescapeMatches == redirect.unescapeMatches
- && this.escapeMatches == redirect.escapeMatches
+ && this.processMatches == redirect.processMatches
&& this.appliesTo.toString() == redirect.appliesTo.toString();
},
@@ -73,8 +72,7 @@ Redirect.prototype = {
excludePattern : this.excludePattern,
redirectUrl : this.redirectUrl,
patternType : this.patternType,
- unescapeMatches : this.unescapeMatches,
- escapeMatches : this.escapeMatches,
+ processMatches : this.processMatches,
disabled : this.disabled,
appliesTo : this.appliesTo.slice(0)
};
@@ -210,8 +208,14 @@ Redirect.prototype = {
this.excludePattern = o.excludePattern || '';
this.redirectUrl = o.redirectUrl || '';
this.patternType = o.patternType || Redirect.WILDCARD;
- this.unescapeMatches = !!o.unescapeMatches;
- this.escapeMatches = !!o.escapeMatches;
+ this.processMatches = o.processMatches || 'noProcessing';
+ if (!o.processMatches && o.unescapeMatches) {
+ this.processMatches = 'urlDecode';
+ }
+ if (!o.processMatches && o.escapeMatches) {
+ this.processMatches = 'urlEncode';
+ }
+
this.disabled = !!o.disabled;
if (o.appliesTo && o.appliesTo.length) {
this.appliesTo = o.appliesTo.slice(0);
@@ -235,12 +239,15 @@ Redirect.prototype = {
var resultUrl = this.redirectUrl;
for (var i = 1; i < matches.length; i++) {
var repl = matches[i] || '';
- if (this.unescapeMatches) {
+ if (this.processMatches == 'urlDecode') {
repl = unescape(repl);
}
- if (this.escapeMatches) {
+ if (this.processMatches == 'urlEncode') {
repl = encodeURIComponent(repl);
}
+ if (this.processMatches == 'base64decode') {
+ repl = atob(repl);
+ }
resultUrl = resultUrl.replace(new RegExp('\\$' + i, 'gi'), repl);
}
this._rxInclude.lastIndex = 0;
diff --git a/redirector.html b/redirector.html
index 8483a02..164a8b5 100644
--- a/redirector.html
+++ b/redirector.html
@@ -85,12 +85,19 @@
<div class="input-cell"><input type="text" ng-change="redirect.updateExampleResult()" ng-model="redirect.excludePattern" placeholder="Pattern to exclude certain urls from the redirection"/></div>
</div>
<div>
- <label for="unescape-matches">Unescape matches:</label>
- <div class="input-cell"><input id="unescape-matches" ng-change="redirect.updateExampleResult()" ng-model="redirect.unescapeMatches" type="checkbox"><span class="placeholder">E.g. turn %2Fbar%2Ffoo%3Fx%3D2 into /bar/foo?x=2</span></div>
- </div>
- <div>
- <label for="escape-matches">Escape matches:</label>
- <div class="input-cell"><input id="escape-matches" ng-change="redirect.updateExampleResult()" ng-model="redirect.escapeMatches" type="checkbox"><span class="placeholder">E.g. turn /bar/foo?x=2 into %2Fbar%2Ffoo%3Fx%3D2</span></div>
+ <label for="process-matches">Process matches:</label>
+ <div class="input-cell">
+ <select id="process-matches" ng-model="redirect.processMatches" ng-change="redirect.updateExampleResult()">
+ <option value="noProcessing">No Processing</option>
+ <option value="urlEncode">URL Encode</option>
+ <option value="urlDecode">URL Decode</option>
+ <option value="base64decode">Base64 Decode</option>
+ </select>
+ <span class="placeholder" ng-show="redirect.processMatches=='noProcessing'">Use matches as they are</span>
+ <span class="placeholder" ng-show="redirect.processMatches=='urlEncode'">E.g. turn /bar/foo?x=2 into %2Fbar%2Ffoo%3Fx%3D2</span>
+ <span class="placeholder" ng-show="redirect.processMatches=='urlDecode'">E.g. turn %2Fbar%2Ffoo%3Fx%3D2 into /bar/foo?x=2</span>
+ <span class="placeholder" ng-show="redirect.processMatches=='base64decode'">E.g. turn aHR0cDovL2Nubi5jb20= into http://cnn.com</span>
+ </div>
</div>
<div>
<label>Apply to:</label>