1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-19 17:53:48 +00:00

Simplify check of url for null and whitespace

This commit is contained in:
Daniel James Smith
2021-12-06 20:05:09 +01:00
parent 1e9419747a
commit 492030da4d

View File

@@ -188,14 +188,12 @@ export class Utils {
}
static getHostname(uriString: string): string {
if (uriString == null) {
if (Utils.isNullOrWhitespace(uriString)) {
return null;
}
uriString = uriString.trim();
if (uriString === '') {
return null;
}
// Does uriString contain invalid characters
// TODO Needs to possibly be extended, although '!' is a reserved character
if (uriString.indexOf('!') > 0) {
@@ -220,14 +218,11 @@ export class Utils {
}
static getDomain(uriString: string): string {
if (uriString == null) {
if (Utils.isNullOrWhitespace(uriString)) {
return null;
}
uriString = uriString.trim();
if (uriString === '') {
return null;
}
if (uriString.startsWith('data:')) {
return null;
@@ -308,14 +303,11 @@ export class Utils {
static getUrl(uriString: string): URL {
if (uriString == null) {
if (this.isNullOrWhitespace(uriString)) {
return null;
}
uriString = uriString.trim();
if (uriString === '') {
return null;
}
let url = Utils.getUrlObject(uriString);
if (url == null) {