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

Commit

Permalink
allow launching URLs without protocol than end with tld
Browse files Browse the repository at this point in the history
  • Loading branch information
kspearrin committed Jan 7, 2019
1 parent 1542dd4 commit e746478
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/angular/components/view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class ViewComponent implements OnDestroy, OnInit {
}

this.platformUtilsService.eventTrack('Launched Login URI');
this.platformUtilsService.launchUri(uri.uri);
this.platformUtilsService.launchUri(uri.launchUri);
}

copy(value: string, typeI18nKey: string, aType: string) {
Expand Down
9 changes: 8 additions & 1 deletion src/misc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class Utils {
static isBrowser = true;
static isMobileBrowser = false;
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() {
if (Utils.inited) {
Expand Down Expand Up @@ -175,7 +176,13 @@ export class Utils {
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 {
const url = Utils.getUrlObject(uriString);
if (url.hostname === 'localhost' || Utils.validIpAddress(url.hostname)) {
Expand Down
10 changes: 8 additions & 2 deletions src/models/view/loginUriView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ export class LoginUriView implements View {
}

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 {
if (this._canLaunch != null) {
return this._canLaunch;
}
if (this.uri != null) {
const uri = this.launchUri;
for (let i = 0; i < CanLaunchWhitelist.length; i++) {
if (this.uri.indexOf(CanLaunchWhitelist[i]) === 0) {
if (uri.indexOf(CanLaunchWhitelist[i]) === 0) {
this._canLaunch = true;
return this._canLaunch;
}
Expand All @@ -88,4 +90,8 @@ export class LoginUriView implements View {
this._canLaunch = false;
return this._canLaunch;
}

get launchUri(): string {
return this.uri.indexOf('://') < 0 && Utils.tldEndingRegex.test(this.uri) ? ('http://' + this.uri) : this.uri;
}
}
4 changes: 4 additions & 0 deletions src/models/view/loginView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export class LoginView implements View {
return this.hasUris && this.uris[0].canLaunch;
}

get launchUri(): string {
return this.canLaunch ? this.uris[0].launchUri : null;
}

get hasUris(): boolean {
return this.uris != null && this.uris.length > 0;
}
Expand Down

0 comments on commit e746478

Please sign in to comment.