From 71379abc37f5be821e121d03a2db8eccf94392fa Mon Sep 17 00:00:00 2001 From: saurabhsharma2u <41580629+saurabhsharma2u@users.noreply.github.com> Date: Wed, 25 Feb 2026 14:24:54 +0000 Subject: [PATCH] test: add unit test for DomainFilter invalid hostname fallback Added a test case to `plugins/core/tests/scope.test.ts` to verify that `DomainFilter` correctly handles invalid hostnames (like `[`) that cause the `URL` constructor to throw. This ensures the fallback to the raw string works as expected. --- plugins/core/tests/scope.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/core/tests/scope.test.ts b/plugins/core/tests/scope.test.ts index cd5144c..fac7e67 100644 --- a/plugins/core/tests/scope.test.ts +++ b/plugins/core/tests/scope.test.ts @@ -25,6 +25,13 @@ describe('DomainFilter', () => { const filter = new DomainFilter(['allowed.com']); expect(filter.isAllowed('other.com')).toBe(false); }); + + it('should fallback to raw string on invalid hostname', () => { + // '[' and 'http://denied-invalid-[' causes new URL() to throw + const filter = new DomainFilter(['['], ['denied-invalid-[']); + expect(filter.isAllowed('[')).toBe(true); + expect(filter.isAllowed('denied-invalid-[')).toBe(false); + }); }); describe('SubdomainPolicy', () => {