From 48878c0b38717134467e0fe69457a803263073cd Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Fri, 22 Jan 2021 18:27:50 +0000 Subject: [PATCH] fix(core): update --- test/test.domain.ts | 2 +- ts/smartstring.domain.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/test/test.domain.ts b/test/test.domain.ts index 91cceee..2ac6daa 100644 --- a/test/test.domain.ts +++ b/test/test.domain.ts @@ -25,7 +25,7 @@ tap.test('expect have the correct protocol', async () => { expect(testDomain.protocol).equal('https'); }); tap.test('testDomain2 expect be a basic domain', async () => { - testDomain2 = new smartstring.Domain('bleu.de'); + testDomain2 = new smartstring.Domain('testing.bleu.de'); console.log(testDomain2); }); diff --git a/ts/smartstring.domain.ts b/ts/smartstring.domain.ts index 8b19ffa..03d11a6 100644 --- a/ts/smartstring.domain.ts +++ b/ts/smartstring.domain.ts @@ -17,11 +17,15 @@ export class Domain { public nodeParsedUrl: plugins.url.UrlWithStringQuery; constructor(domainStringArg: string) { // lets do the node standard stuff first + this.protocol = this._protocolRegex(domainStringArg); + if (!this.protocol) { + domainStringArg = `https://${domainStringArg}` + } this.nodeParsedUrl = plugins.url.parse(domainStringArg); this.port = this.nodeParsedUrl.port; // lets do the rest after - const regexMatches = this._domainRegex(domainStringArg.replace(this.nodeParsedUrl.path, '')); + const regexMatches = this._domainRegex(domainStringArg.replace(this.nodeParsedUrl.pathname, '')); this.fullName = ''; for (let i = 1; i <= 5; i++) { if (regexMatches[i - 1]) { @@ -36,7 +40,6 @@ export class Domain { this['level' + i.toString()] = undefined; } } - this.protocol = this._protocolRegex(domainStringArg); this.zoneName = this.level2 + '.' + this.level1; // aliases