Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex bug fix #169

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ function checkPattern(pattern, type) {
return regex;
}




function showResult(text, fail) {

fail && result.classList.add('alert');
Expand Down
5 changes: 2 additions & 3 deletions src/scripts/matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/scripts/pattern-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
5 changes: 5 additions & 0 deletions src/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down