Skip to content

Commit 1fd3930

Browse files
committed
Allow sub-sub-domains by * wildcard
1 parent 0c8698b commit 1fd3930

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

src/utils/url.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ function matchURLPattern(url: string, pattern: string) {
215215

216216
if (
217217
p.hostParts.length >= 2
218+
&& p.hostParts.at(-1) !== '*'
218219
&& (
219220
p.hostParts.length < u.hostParts.length - 1
220221
|| (

tests/unit/utils/url.tests.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ describe('Domain utilities', () => {
4646
expect(isURLMatched('https://xyz.example.com/page/1', 'example.com')).toEqual(false);
4747
expect(isURLMatched('https://xyz.www.example.com/page/1', 'example.com')).toEqual(false);
4848

49+
expect(isURLMatched('https://xyz.example.com/page/1', '*.example.com')).toEqual(true);
50+
expect(isURLMatched('https://abc.xyz.example.com/page/1', '*.example.com')).toEqual(true);
51+
expect(isURLMatched('https://xyz.failure.com/page/1', '*.example.com')).toEqual(false);
52+
4953
expect(isURLMatched('https://www.example.com/page/1', 'example.com/page')).toEqual(true);
5054
expect(isURLMatched('https://www.example.com/fail/1', 'example.com/page')).toEqual(false);
5155

0 commit comments

Comments
 (0)