diff --git a/src/scripts/common.js b/src/scripts/common.js index bd516c8..7bf8b06 100644 --- a/src/scripts/common.js +++ b/src/scripts/common.js @@ -52,9 +52,6 @@ function checkPattern(pattern, type) { return regex; } - - - function showResult(text, fail) { fail && result.classList.add('alert'); diff --git a/src/scripts/matcher.js b/src/scripts/matcher.js index 19cd49d..c85e589 100644 --- a/src/scripts/matcher.js +++ b/src/scripts/matcher.js @@ -25,14 +25,13 @@ function findProxyMatch(url, activeSettings) { // before using other parts of URL. For now, we ignore the other parts. const parsedUrl = new URL(url); const scheme = parsedUrl.protocol.substring(0, parsedUrl.protocol.length-1); // strip the colon - const hostPort = parsedUrl.host; // This includes port if one is specified for (const proxy of activeSettings.proxySettings) { // Check black patterns first const blackMatch = proxy.blackPatterns.find(item => (item.protocols === schemeSet.all || item.protocols === schemeSet[scheme]) && - item.pattern.test(hostPort)); + item.pattern.test(Utils.getUrlStrByPatternType(item.type, parsedUrl))); if (blackMatch) { sendToMatchedLog(url, proxy, Utils.getProxyTitle(proxy), blackMatch, BLACK); @@ -41,7 +40,7 @@ function findProxyMatch(url, activeSettings) { const whiteMatch = proxy.whitePatterns.find(item => (item.protocols === schemeSet.all || item.protocols === schemeSet[scheme]) && - item.pattern.test(hostPort)); + item.pattern.test(Utils.getUrlStrByPatternType(item.type, parsedUrl))); if (whiteMatch) { // found a whitelist match, end here diff --git a/src/scripts/pattern-tester.js b/src/scripts/pattern-tester.js index 31d4b3f..3bdb543 100644 --- a/src/scripts/pattern-tester.js +++ b/src/scripts/pattern-tester.js @@ -60,13 +60,15 @@ function testPattern() { return; } - + // --- pattern check const regex = checkPattern(pattern, type); if (!regex) { return; } + parsedURL = Utils.getUrlStrByPatternType(type.value, parsedURL); + // --- pattern on URL check (pattern is valid) - regex.test(parsedURL.host) ? showResult(chrome.i18n.getMessage('patternMatch')) : + regex.test(parsedURL) ? showResult(chrome.i18n.getMessage('patternMatch')) : showResult(chrome.i18n.getMessage('patternNotMatch'), true); } diff --git a/src/scripts/utils.js b/src/scripts/utils.js index 263e33a..6126aad 100644 --- a/src/scripts/utils.js +++ b/src/scripts/utils.js @@ -249,6 +249,11 @@ class Utils { } } + static getUrlStrByPatternType(type, parsedURL) { + return (type == PATTERN_TYPE_REGEXP) + ? parsedURL : parsedURL.host; + } + /* // utils only used for export, will be removed as DB format export is adapted static prepareForSettings(settings = {}) {