From bb29fb312264dba57cca09e75564753fb3033c10 Mon Sep 17 00:00:00 2001 From: Erayd Date: Mon, 15 Apr 2019 01:21:51 +1200 Subject: [PATCH] Assume current domain is valid, even if the TLD is not (#107) --- src/background.js | 14 ++++++++++---- src/popup/popup.js | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/background.js b/src/background.js index d2391c5..2ab4ae6 100644 --- a/src/background.js +++ b/src/background.js @@ -57,17 +57,23 @@ chrome.runtime.onInstalled.addListener(onExtensionInstalled); * * @since 3.0.0 * - * @param string path Path to parse + * @param string path Path to parse + * @param string currentHost Current hostname for the active tab * @return string|null Extracted domain */ -function pathToDomain(path) { +function pathToDomain(path, currentHost) { var parts = path.split(/\//).reverse(); for (var key in parts) { if (parts[key].indexOf("@") >= 0) { continue; } var t = TldJS.parse(parts[key]); - if (t.isValid && t.tldExists && t.domain !== null) { + if ( + t.isValid && + ((t.tldExists && t.domain !== null) || + t.hostname === currentHost || + currentHost.endsWith(`.${t.hostname}`)) + ) { return t.hostname; } } @@ -104,7 +110,7 @@ async function updateMatchingPasswordsCount(tabId) { for (var storeId in response.data.files) { for (var key in response.data.files[storeId]) { const login = response.data.files[storeId][key].replace(/\.gpg$/i, ""); - const domain = pathToDomain(storeId + "/" + login); + const domain = pathToDomain(storeId + "/" + login, currentDomain); const inCurrentDomain = currentDomain === domain || currentDomain.endsWith("." + domain); const recent = settings.recent[sha1(currentDomain + sha1(storeId + sha1(login)))]; diff --git a/src/popup/popup.js b/src/popup/popup.js index 30cf842..eda6af7 100644 --- a/src/popup/popup.js +++ b/src/popup/popup.js @@ -34,17 +34,23 @@ function handleError(error, type = "error") { * * @since 3.0.0 * - * @param string path Path to parse + * @param string path Path to parse + * @param string currentHost Current hostname for the active tab * @return string|null Extracted domain */ -function pathToDomain(path) { +function pathToDomain(path, currentHost) { var parts = path.split(/\//).reverse(); for (var key in parts) { if (parts[key].indexOf("@") >= 0) { continue; } var t = TldJS.parse(parts[key]); - if (t.isValid && t.tldExists && t.domain !== null) { + if ( + t.isValid && + ((t.tldExists && t.domain !== null) || + t.hostname === currentHost || + currentHost.endsWith(`.${t.hostname}`)) + ) { return t.hostname; } } @@ -92,7 +98,7 @@ async function run() { login: response.files[storeId][key].replace(/\.gpg$/i, ""), allowFill: true }; - login.domain = pathToDomain(storeId + "/" + login.login); + login.domain = pathToDomain(storeId + "/" + login.login, settings.host); login.inCurrentDomain = settings.host == login.domain || settings.host.endsWith("." + login.domain); login.recent =