1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-23 11:56:00 +01:00

fixes to url parsing (#99)

* fixes to url parsing

* make it a little more intelligent to pass tests
This commit is contained in:
Kyle Spearrin 2020-04-29 11:47:34 -04:00 committed by GitHub
parent 5e24e396ab
commit 0092aac275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -281,14 +281,14 @@ export class Utils {
return null;
}
const hasProtocol = uriString.indexOf('://') > -1;
if (!hasProtocol && uriString.indexOf('.') > -1) {
uriString = 'http://' + uriString;
} else if (!hasProtocol) {
return null;
let url = Utils.getUrlObject(uriString);
if (url == null) {
const hasHttpProtocol = uriString.indexOf('http://') === 0 || uriString.indexOf('https://') === 0;
if (!hasHttpProtocol && uriString.indexOf('.') > -1) {
url = Utils.getUrlObject('http://' + uriString);
}
}
return Utils.getUrlObject(uriString);
return url;
}
private static getUrlObject(uriString: string): URL {
@ -298,6 +298,12 @@ export class Utils {
} else if (typeof URL === 'function') {
return new URL(uriString);
} else if (window != null) {
const hasProtocol = uriString.indexOf('://') > -1;
if (!hasProtocol && uriString.indexOf('.') > -1) {
uriString = 'http://' + uriString;
} else if (!hasProtocol) {
return null;
}
const anchor = window.document.createElement('a');
anchor.href = uriString;
return anchor as any;