Skip to content

Commit a04bf8d

Browse files
authored
Removed unused "are paths equal?" helper (TryGhost#27498)
ref fee402a We had a utility function, `arePathsEqual`, which has been unused since fee402a. Let's remove it. `git grep arePathsEqual` returns no results after this change.
1 parent aa41aba commit a04bf8d

2 files changed

Lines changed: 1 addition & 89 deletions

File tree

apps/admin-x-settings/src/utils/url.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,3 @@ export function trimSearchAndHash(url: URL) {
1313
url.hash = '';
1414
return url;
1515
}
16-
17-
/* Compare two URLs based on their hostname and pathname.
18-
* Query params, hash fragements, protocol and www are ignored.
19-
*
20-
* Example:
21-
* - https://a.com, http://a.com, https://www.a.com, https://a.com?param1=value, https://a.com/#segment-1 are all considered equal
22-
* - but, https://a.com/path-1 and https://a.com/path-2 are not
23-
*/
24-
export function arePathsEqual(urlStr1: string, urlStr2: string) {
25-
let url1, url2;
26-
27-
try {
28-
url1 = new URL(urlStr1);
29-
url2 = new URL(urlStr2);
30-
} catch {
31-
return false;
32-
}
33-
34-
return (
35-
url1.hostname.replace('www.', '') === url2.hostname.replace('www.', '') &&
36-
url1.pathname === url2.pathname
37-
);
38-
}
Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as assert from 'assert/strict';
2-
import {arePathsEqual, trimHash, trimSearch, trimSearchAndHash} from '@src/utils/url';
2+
import {trimHash, trimSearch, trimSearchAndHash} from '@src/utils/url';
33

44
describe('trimSearch', function () {
55
it('removes the query parameters from a URL', function () {
@@ -27,68 +27,3 @@ describe('trimSearchAndHash', function () {
2727
assert.equal(trimSearchAndHash(parsedUrl).toString(), 'https://example.com/path');
2828
});
2929
});
30-
31-
describe('arePathsEqual', function () {
32-
it('returns false if one of the param is not a URL', function () {
33-
const url1 = 'foo';
34-
const url2 = 'https://example.com';
35-
36-
assert.equal(arePathsEqual(url1, url2), false);
37-
});
38-
39-
it('returns false if hostnames are different', function () {
40-
const url1 = 'https://a.com';
41-
const url2 = 'https://b.com';
42-
43-
assert.equal(arePathsEqual(url1, url2), false);
44-
});
45-
46-
it('returns false if top level domains are different', function () {
47-
const url1 = 'https://a.io';
48-
const url2 = 'https://a.com';
49-
50-
assert.equal(arePathsEqual(url1, url2), false);
51-
});
52-
53-
it('returns false if sub domains are different', function () {
54-
const url1 = 'https://sub.a.com';
55-
const url2 = 'https://subdiff.a.com';
56-
57-
assert.equal(arePathsEqual(url1, url2), false);
58-
});
59-
60-
it('returns false if paths are different', function () {
61-
const url1 = 'https://a.com/path-1';
62-
const url2 = 'https://a.com/path-2';
63-
64-
assert.equal(arePathsEqual(url1, url2), false);
65-
});
66-
67-
it('returns true even if protocols are different', function () {
68-
const url1 = 'http://a.com';
69-
const url2 = 'https://a.com';
70-
71-
assert.equal(arePathsEqual(url1, url2), true);
72-
});
73-
74-
it('returns true even if www is used in one of the urls', function () {
75-
const url1 = 'https://www.a.com';
76-
const url2 = 'https://a.com';
77-
78-
assert.equal(arePathsEqual(url1, url2), true);
79-
});
80-
81-
it('returns true even if query parameters are different', function () {
82-
const url1 = 'http://a.com?foo=bar';
83-
const url2 = 'http://a.com';
84-
85-
assert.equal(arePathsEqual(url1, url2), true);
86-
});
87-
88-
it('returns true even if hash segments are different', function () {
89-
const url1 = 'http://a.com#segment-1';
90-
const url2 = 'http://a.com';
91-
92-
assert.equal(arePathsEqual(url1, url2), true);
93-
});
94-
});

0 commit comments

Comments
 (0)