Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 97ab6d5

Browse files
committed
fix issue when a domain was not correctly displayed for post links
1 parent 71f5261 commit 97ab6d5

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/utils/__tests__/links.spec.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,20 @@ test('get a domain when the url has ws://', () => {
2020
expect(getDomainFromUrl(url)).toEqual('zoonk.org');
2121
});
2222

23-
test('get a domain when the url has www.', () => {
24-
const url = 'http://www.zoonk.org/some/random/path?q=123';
23+
test('get a domain when the url has a subdomain.', () => {
24+
const url = 'http://dev.zoonk.org/some/random/path?q=123';
2525
const url2 = 'https://www.zoonk.org/some/random/path?q=123';
2626
const url3 = 'www.zoonk.org/some/random/path?q=123';
27-
expect(getDomainFromUrl(url)).toEqual('zoonk.org');
28-
expect(getDomainFromUrl(url2)).toEqual('zoonk.org');
27+
expect(getDomainFromUrl(url)).toEqual('dev.zoonk.org');
28+
expect(getDomainFromUrl(url2)).toEqual('www.zoonk.org');
2929
expect(getDomainFromUrl(url3)).toEqual('unknown');
3030
});
3131

32-
test('get a domain when the url has a subdomain', () => {});
32+
test('get a domain for urls with multiple paths', () => {
33+
const url = 'http://zoonk.com.br/some/random/path?q=123';
34+
const url2 = 'https://zoonk.co.uk/some/random/path?q=123';
35+
const url3 = 'zoonk.com.br/some/random/path?q=123';
36+
expect(getDomainFromUrl(url)).toEqual('zoonk.com.br');
37+
expect(getDomainFromUrl(url2)).toEqual('zoonk.co.uk');
38+
expect(getDomainFromUrl(url3)).toEqual('unknown');
39+
});

src/utils/links.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ export const containsYoutubeUrl = (text?: string | null): string | null => {
1717
export const getDomainFromUrl = (url: string): string => {
1818
try {
1919
const { host } = new URL(url);
20-
let domain = host.split('.');
21-
domain = domain.slice(domain.length - 2);
22-
return domain.join('.');
20+
return host;
2321
} catch (e) {
2422
return 'unknown';
2523
}

0 commit comments

Comments
 (0)