From fa956099794c23b5817557bf3e77b7a0b66a6ab2 Mon Sep 17 00:00:00 2001 From: Farrow <93874202+Faris-07@users.noreply.github.com> Date: Sun, 20 Feb 2022 15:00:28 +0000 Subject: [PATCH 1/3] rm whitespace --- src/scripts/common.js | 3 --- 1 file changed, 3 deletions(-) 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'); From 60c015387be5ea68851a5a5cdf5913d3235a8296 Mon Sep 17 00:00:00 2001 From: Farrow <93874202+Faris-07@users.noreply.github.com> Date: Sun, 20 Feb 2022 17:27:11 +0000 Subject: [PATCH 2/3] fixed bugs that always default to type=wildcard and do not use ECMA regex when type="Reg Exp" is selected for a pattern. --- src/scripts/matcher.js | 7 +++---- src/scripts/pattern-tester.js | 6 ++++-- src/scripts/utils.js | 5 +++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/scripts/matcher.js b/src/scripts/matcher.js index 19cd49d..2fc3c46 100644 --- a/src/scripts/matcher.js +++ b/src/scripts/matcher.js @@ -25,23 +25,22 @@ 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); continue; // if blacklist matched, continue to the next proxy } - const whiteMatch = proxy.whitePatterns.find(item => + 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 = {}) { From ca36f948c5ea3c63fffca5ce4005fee8b28ba35a Mon Sep 17 00:00:00 2001 From: Farrow <93874202+Faris-07@users.noreply.github.com> Date: Sun, 20 Feb 2022 19:06:20 +0000 Subject: [PATCH 3/3] minor syntax and whitespace fixes --- src/scripts/matcher.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scripts/matcher.js b/src/scripts/matcher.js index 2fc3c46..c85e589 100644 --- a/src/scripts/matcher.js +++ b/src/scripts/matcher.js @@ -38,9 +38,9 @@ function findProxyMatch(url, activeSettings) { continue; // if blacklist matched, continue to the next proxy } - const whiteMatch = proxy.whitePatterns.find(item => + const whiteMatch = proxy.whitePatterns.find(item => (item.protocols === schemeSet.all || item.protocols === schemeSet[scheme]) && - item.pattern.test(Utils.getUrlStrByPatternType(item.type, parsedUrl)));; + item.pattern.test(Utils.getUrlStrByPatternType(item.type, parsedUrl))); if (whiteMatch) { // found a whitelist match, end here