1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-25 20:53:28 +00:00

Add try/catch around tldts method calls

This commit is contained in:
Daniel James Smith
2021-12-06 20:09:43 +01:00
parent 4240eaeb23
commit fde063f51a

View File

@@ -200,11 +200,14 @@ export class Utils {
return null;
}
const hostname = tldts.getHostname(uriString, { validHosts: this.validHosts });
if (hostname != null) {
return hostname;
try {
const hostname = tldts.getHostname(uriString, { validHosts: this.validHosts });
if (hostname != null) {
return hostname;
}
} catch {
return null;
}
return null;
}
@@ -235,19 +238,21 @@ export class Utils {
httpUrl = true;
}
try {
const parseResult = tldts.parse(uriString, { validHosts: this.validHosts });
if (parseResult != null && parseResult.hostname != null) {
if (parseResult.hostname === 'localhost' || parseResult.isIp) {
return parseResult.hostname;
}
const parseResult = tldts.parse(uriString, { validHosts: this.validHosts });
if (parseResult != null && parseResult.hostname != null) {
if (parseResult.hostname === 'localhost' || parseResult.isIp) {
return parseResult.hostname;
}
if (parseResult.domain != null) {
return parseResult.domain;
if (parseResult.domain != null) {
return parseResult.domain;
}
return null;
}
} catch {
return null;
}
return null;
}