From 96397b66079d524f223911f882e3521396c4900c Mon Sep 17 00:00:00 2001 From: Einar Egilsson Date: Sun, 8 Jan 2012 06:57:05 +0100 Subject: 2.7.1 --- chrome/js/redirector-ui.js | 49 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) (limited to 'chrome/js/redirector-ui.js') 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])); -- cgit v1.2.3-70-g09d2