diff options
| author | dakkar <dakkar@thenautilus.net> | 2024-11-27 14:44:33 +0000 |
|---|---|---|
| committer | dakkar <dakkar@thenautilus.net> | 2024-11-29 11:39:18 +0000 |
| commit | 51afbbaf72eb88e1a1014cdf34c6b064d8490cd2 (patch) | |
| tree | 9f82aa9924f02bfe9f638a3405670f16d6436e56 | |
| parent | actually use the correct `import` syntax (diff) | |
| download | sharkey-51afbbaf72eb88e1a1014cdf34c6b064d8490cd2.tar.gz sharkey-51afbbaf72eb88e1a1014cdf34c6b064d8490cd2.tar.bz2 sharkey-51afbbaf72eb88e1a1014cdf34c6b064d8490cd2.zip | |
handle `.masto.host` specially
| -rw-r--r-- | packages/backend/src/core/UtilityService.ts | 14 | ||||
| -rw-r--r-- | packages/backend/test/unit/UtilityService.ts | 4 |
2 files changed, 17 insertions, 1 deletions
diff --git a/packages/backend/src/core/UtilityService.ts b/packages/backend/src/core/UtilityService.ts index fc38c9dac6..dda4bd5fbd 100644 --- a/packages/backend/src/core/UtilityService.ts +++ b/packages/backend/src/core/UtilityService.ts @@ -123,10 +123,22 @@ export class UtilityService { return host; } + private specialSuffix(hostname: string): string | null { + // masto.host provides domain names for its clients, we have to + // treat it as if it were a public suffix + const mastoHost = hostname.match(/\.?([a-zA-Z0-9-]+\.masto\.host)$/i); + if (mastoHost) { + return mastoHost[1]; + } + + return null; + } + @bindThis public punyHostPSLDomain(url: string): string { const urlObj = new URL(url); - const domain = psl.get(urlObj.hostname) ?? urlObj.hostname; + const hostname = urlObj.hostname; + const domain = this.specialSuffix(hostname) ?? psl.get(hostname) ?? hostname; const host = `${this.toPuny(domain)}${urlObj.port.length > 0 ? ':' + urlObj.port : ''}`; return host; } diff --git a/packages/backend/test/unit/UtilityService.ts b/packages/backend/test/unit/UtilityService.ts index 837b55206e..d86e794f2f 100644 --- a/packages/backend/test/unit/UtilityService.ts +++ b/packages/backend/test/unit/UtilityService.ts @@ -35,5 +35,9 @@ describe('UtilityService', () => { assert.equal(utilityService.punyHostPSLDomain('http://foo.github.io'), 'foo.github.io'); assert.equal(utilityService.punyHostPSLDomain('http://foo.bar.github.io'), 'bar.github.io'); }); + test('special', () => { + assert.equal(utilityService.punyHostPSLDomain('http://foo.masto.host'), 'foo.masto.host'); + assert.equal(utilityService.punyHostPSLDomain('http://foo.bar.masto.host'), 'bar.masto.host'); + }); }); }); |