mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-27 10:20:27 +01:00
parent
cf357b833c
commit
fccc2b06b6
2 changed files with 1 additions and 17 deletions
|
@ -123,22 +123,10 @@ export class UtilityService {
|
||||||
return host;
|
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
|
@bindThis
|
||||||
public punyHostPSLDomain(url: string): string {
|
public punyHostPSLDomain(url: string): string {
|
||||||
const urlObj = new URL(url);
|
const urlObj = new URL(url);
|
||||||
const hostname = urlObj.hostname;
|
const domain = psl.get(urlObj.hostname) ?? urlObj.hostname;
|
||||||
const domain = this.specialSuffix(hostname) ?? psl.get(hostname) ?? hostname;
|
|
||||||
const host = `${this.toPuny(domain)}${urlObj.port.length > 0 ? ':' + urlObj.port : ''}`;
|
const host = `${this.toPuny(domain)}${urlObj.port.length > 0 ? ':' + urlObj.port : ''}`;
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,9 +35,5 @@ describe('UtilityService', () => {
|
||||||
assert.equal(utilityService.punyHostPSLDomain('http://foo.github.io'), 'foo.github.io');
|
assert.equal(utilityService.punyHostPSLDomain('http://foo.github.io'), 'foo.github.io');
|
||||||
assert.equal(utilityService.punyHostPSLDomain('http://foo.bar.github.io'), 'bar.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');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue