Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
fixes to url parsing (#99)
Browse files Browse the repository at this point in the history
* fixes to url parsing

* make it a little more intelligent to pass tests
  • Loading branch information
kspearrin committed Apr 29, 2020
1 parent 5e24e39 commit 0092aac
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/misc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down

0 comments on commit 0092aac

Please sign in to comment.