mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-06 00:48:08 +02:00
fixes to url parsing (#99)
* fixes to url parsing * make it a little more intelligent to pass tests
This commit is contained in:
parent
5e24e396ab
commit
0092aac275
@ -281,14 +281,14 @@ export class Utils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasProtocol = uriString.indexOf('://') > -1;
|
let url = Utils.getUrlObject(uriString);
|
||||||
if (!hasProtocol && uriString.indexOf('.') > -1) {
|
if (url == null) {
|
||||||
uriString = 'http://' + uriString;
|
const hasHttpProtocol = uriString.indexOf('http://') === 0 || uriString.indexOf('https://') === 0;
|
||||||
} else if (!hasProtocol) {
|
if (!hasHttpProtocol && uriString.indexOf('.') > -1) {
|
||||||
return null;
|
url = Utils.getUrlObject('http://' + uriString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return url;
|
||||||
return Utils.getUrlObject(uriString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getUrlObject(uriString: string): URL {
|
private static getUrlObject(uriString: string): URL {
|
||||||
@ -298,6 +298,12 @@ export class Utils {
|
|||||||
} else if (typeof URL === 'function') {
|
} else if (typeof URL === 'function') {
|
||||||
return new URL(uriString);
|
return new URL(uriString);
|
||||||
} else if (window != null) {
|
} 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');
|
const anchor = window.document.createElement('a');
|
||||||
anchor.href = uriString;
|
anchor.href = uriString;
|
||||||
return anchor as any;
|
return anchor as any;
|
||||||
|
Loading…
Reference in New Issue
Block a user