Merge pull request #97 from cilerler/patch-1

Fix whitelist matching issues
This commit is contained in:
Alan Hamlett
2021-01-11 23:58:39 -08:00
committed by GitHub

View File

@@ -147,28 +147,39 @@ class WakaTimeCore {
var lines = list.split('\n'); var lines = list.split('\n');
for (var i = 0; i < lines.length; i++) { for (var i = 0; i < lines.length; i++) {
// Trim all lines from the list one by one // strip (http:// or https://) and trailing (`/` or `@@`)
var cleanLine = lines[i].trim(); var line = lines[i];
var cleanLine = line.trim().replace(/(\/|@@)$/, '').replace(/^(?:https?:\/\/)?/i, '');
// If by any chance one line in the list is empty, ignore it var emptyLine = cleanLine === '';
if (cleanLine === '') { if (emptyLine) {
continue; continue;
} }
var projectIndicatorCharacters = '@@';
// If url contains the current line return object var projectIndicatorIndex = cleanLine.lastIndexOf(projectIndicatorCharacters);
if (url.indexOf(cleanLine.split('@@')[0]) > -1) { var projectIndicatorExists = projectIndicatorIndex > -1;
if (cleanLine.split('@@')[1]) { var projectName = null;
return { var urlFromLine = cleanLine;
url: cleanLine.split('@@')[0], if (projectIndicatorExists) {
project: cleanLine.split('@@')[1] var start = projectIndicatorIndex + projectIndicatorCharacters.length;
}; projectName = cleanLine.substring(start);
urlFromLine = cleanLine.replace(cleanLine.substring(projectIndicatorIndex), '').replace(/\/$/, '');
} }
else { var schemaHttpExists = url.match(/^http:\/\//i);
return { var schemaHttpsExists = url.match(/^https:\/\//i);
url: cleanLine.split('@@')[0], var schema = '';
project: null, if (schemaHttpExists) {
}; schema = 'http://';
} }
if (schemaHttpsExists) {
schema = 'https://';
}
var cleanUrl = url.trim().replace(/(\/|@@)$/, '').replace(/^(?:https?:\/\/)?/i, '');
var startsWithUrl = cleanUrl.toLowerCase().indexOf(urlFromLine.toLowerCase()) > -1;
if (startsWithUrl) {
return {
url: schema + urlFromLine,
project: projectName
};
} }
} }