aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chrome/js/redirector-ui.js49
-rw-r--r--locale/en-US/redirector.properties1
2 files changed, 41 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]));
diff --git a/locale/en-US/redirector.properties b/locale/en-US/redirector.properties
index 09e4910..e853787 100644
--- a/locale/en-US/redirector.properties
+++ b/locale/en-US/redirector.properties
@@ -8,6 +8,7 @@ disabledTooltip=Redirector is disabled
testPatternSuccess=The pattern %S matches example URL %S, and would redirect you to url: %S
testPatternFailure=The pattern %S does not match example URL %S
testPatternExclude=Example URL %S matches the exclude pattern %S and so would not be redirected
+regexPatternErrorTitle=Invalid regular expression
regexPatternError=The pattern '%S' is not a legal regular expression pattern. Details: %S
xpathDeprecated=XPath patterns are no longer supported as of version 1.5.1, please remove those redirects.
redirectorFiles=Redirector files (*.rjson)