aboutsummaryrefslogtreecommitdiff
path: root/chrome/js
diff options
context:
space:
mode:
authorEinar Egilsson2012-01-08 06:57:05 +0100
committerEinar Egilsson2012-01-08 06:57:05 +0100
commit96397b66079d524f223911f882e3521396c4900c (patch)
tree87c08bb3ae9c03e3635e48cd4b349ac2ec077264 /chrome/js
parent5a68a9c070e45f4a8366f0baed90befe685f2824 (diff)
2.7.1
Diffstat (limited to 'chrome/js')
-rw-r--r--chrome/js/redirector-ui.js49
1 files changed, 40 insertions, 9 deletions
diff --git a/chrome/js/redirector-ui.js b/chrome/js/redirector-ui.js
index 53b8892..8deb20d 100644
--- a/chrome/js/redirector-ui.js
+++ b/chrome/js/redirector-ui.js
@@ -22,6 +22,19 @@ function tr(name, args) {
}
}
+function validatePattern(pattern, patternType) {
+ if (patternType != Redirect.REGEX) {
+ return true;
+ }
+ try {
+ var rx = new RegExp(pattern)
+ return true;
+ } catch(e) {
+ alert(tr('regexPatternErrorTitle'), tr('regexPatternError', [pattern, e.toString()]));
+ return false;
+ }
+}
+
function validateRedirect(redirect) {
if (!/^\s*$/.test(redirect.exampleUrl)) {
var result = redirect.getMatch(redirect.exampleUrl);
@@ -145,24 +158,37 @@ function showRedirect(redirect) {
}
function controlsToRedirect(redirect) {
- redirect.description = $('#description').val();
- redirect.exampleUrl = $('#example-url').val();
- redirect.includePattern = $('#include-pattern').val();
- redirect.excludePattern = $('#exclude-pattern').val();
- redirect.redirectUrl = $('#redirect-to').val();
- redirect.disabled = !$('#redirect-enabled').attr('checked');
- redirect.unescapeMatches = $('#unescape-matches').attr('checked');
if ($('#regex-pattern').attr('checked')) {
redirect.patternType = Redirect.REGEX;
} else {
redirect.patternType = Redirect.WILDCARD;
}
+
+ var inc = $('#include-pattern').val();
+ var exc = $('#exclude-pattern').val();
+ if (!validatePattern(inc, redirect.patternType)) {
+ return false;
+ }
+ if (!validatePattern(exc, redirect.patternType)) {
+ return false;
+ }
+ redirect.includePattern = inc;
+ redirect.excludePattern = exc;
+
+ redirect.description = $('#description').val();
+ redirect.exampleUrl = $('#example-url').val();
+ redirect.redirectUrl = $('#redirect-to').val();
+ redirect.disabled = !$('#redirect-enabled').attr('checked');
+ redirect.unescapeMatches = $('#unescape-matches').attr('checked');
+ return true;
}
function saveRedirect() {
//First validate:
var tmpRedirect = new Redirect();
- controlsToRedirect(tmpRedirect);
+ if (!controlsToRedirect(tmpRedirect)) {
+ return;
+ }
if (!validateRedirect(tmpRedirect)) {
return;
}
@@ -190,8 +216,13 @@ function bindConfig() {
function testPattern() {
try {
var redirect = new Redirect();
- controlsToRedirect(redirect);
+ if (!controlsToRedirect(redirect)) {
+ return;
+ }
var extName = tr('extensionName');
+ if (!validateRedirect(redirect)) {
+ return;
+ }
var result = redirect.test();
if (result.isMatch) {
alert(extName, tr('testPatternSuccess', [redirect.includePattern, redirect.exampleUrl, result.redirectTo]));