Skip to content

Commit

Permalink
Assume current domain is valid, even if the TLD is not (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
erayd authored Apr 14, 2019
1 parent 0f068a4 commit bb29fb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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)))];
Expand Down
14 changes: 10 additions & 4 deletions src/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit bb29fb3

Please sign in to comment.