allow launching URLs without protocol than end with tld

This commit is contained in:
Kyle Spearrin 2019-01-07 10:33:13 -05:00
parent 1542dd45d3
commit e7464785e1
4 changed files with 21 additions and 4 deletions

View File

@ -134,7 +134,7 @@ export class ViewComponent implements OnDestroy, OnInit {
} }
this.platformUtilsService.eventTrack('Launched Login URI'); this.platformUtilsService.eventTrack('Launched Login URI');
this.platformUtilsService.launchUri(uri.uri); this.platformUtilsService.launchUri(uri.launchUri);
} }
copy(value: string, typeI18nKey: string, aType: string) { copy(value: string, typeI18nKey: string, aType: string) {

View File

@ -12,6 +12,7 @@ export class Utils {
static isBrowser = true; static isBrowser = true;
static isMobileBrowser = false; static isMobileBrowser = false;
static global: any = null; static global: any = null;
static tldEndingRegex = /.*\.(com|net|org|edu|uk|gov|ca|de|jp|fr|au|ru|ch|io|es|us|co|xyz|info|ly|mil)$/;
static init() { static init() {
if (Utils.inited) { if (Utils.inited) {
@ -175,7 +176,13 @@ export class Utils {
return null; return null;
} }
if (uriString.startsWith('http://') || uriString.startsWith('https://')) { let httpUrl = uriString.startsWith('http://') || uriString.startsWith('https://');
if (!httpUrl && Utils.tldEndingRegex.test(uriString)) {
uriString = 'http://' + uriString;
httpUrl = true;
}
if (httpUrl) {
try { try {
const url = Utils.getUrlObject(uriString); const url = Utils.getUrlObject(uriString);
if (url.hostname === 'localhost' || Utils.validIpAddress(url.hostname)) { if (url.hostname === 'localhost' || Utils.validIpAddress(url.hostname)) {

View File

@ -70,7 +70,8 @@ export class LoginUriView implements View {
} }
get isWebsite(): boolean { get isWebsite(): boolean {
return this.uri != null && (this.uri.indexOf('http://') === 0 || this.uri.indexOf('https://') === 0); return this.uri != null && (this.uri.indexOf('http://') === 0 || this.uri.indexOf('https://') === 0 ||
(this.uri.indexOf('://') < 0 && Utils.tldEndingRegex.test(this.uri)));
} }
get canLaunch(): boolean { get canLaunch(): boolean {
@ -78,8 +79,9 @@ export class LoginUriView implements View {
return this._canLaunch; return this._canLaunch;
} }
if (this.uri != null) { if (this.uri != null) {
const uri = this.launchUri;
for (let i = 0; i < CanLaunchWhitelist.length; i++) { for (let i = 0; i < CanLaunchWhitelist.length; i++) {
if (this.uri.indexOf(CanLaunchWhitelist[i]) === 0) { if (uri.indexOf(CanLaunchWhitelist[i]) === 0) {
this._canLaunch = true; this._canLaunch = true;
return this._canLaunch; return this._canLaunch;
} }
@ -88,4 +90,8 @@ export class LoginUriView implements View {
this._canLaunch = false; this._canLaunch = false;
return this._canLaunch; return this._canLaunch;
} }
get launchUri(): string {
return this.uri.indexOf('://') < 0 && Utils.tldEndingRegex.test(this.uri) ? ('http://' + this.uri) : this.uri;
}
} }

View File

@ -34,6 +34,10 @@ export class LoginView implements View {
return this.hasUris && this.uris[0].canLaunch; return this.hasUris && this.uris[0].canLaunch;
} }
get launchUri(): string {
return this.canLaunch ? this.uris[0].launchUri : null;
}
get hasUris(): boolean { get hasUris(): boolean {
return this.uris != null && this.uris.length > 0; return this.uris != null && this.uris.length > 0;
} }