diff --git a/packages/match-patterns/src/index.test.ts b/packages/match-patterns/src/index.test.ts index 5ae7550..aa6b760 100644 --- a/packages/match-patterns/src/index.test.ts +++ b/packages/match-patterns/src/index.test.ts @@ -15,6 +15,7 @@ describe('MatchPattern', () => { it.each([ [true, 'http://google.com'], [true, new URL('https://youtube.com')], + [true, new URL('file:///home/aklinker1')], [true, { hostname: 'test.com', pathname: '/', protocol: 'http:' } as Location], ])('should parse "%s", when "%s" is checked, return %s', (exepcted, url) => { expect(new MatchPattern('').includes(url)).toBe(exepcted); diff --git a/packages/match-patterns/src/index.ts b/packages/match-patterns/src/index.ts index 0f8e5cc..a342385 100644 --- a/packages/match-patterns/src/index.ts +++ b/packages/match-patterns/src/index.ts @@ -13,6 +13,7 @@ export class MatchPattern { private protocolMatches: string[]; private hostnameMatch: string | undefined; private pathnameMatch: string | undefined; + private isAllUrls?: boolean; /** * Parse a match pattern string. If it is invalid, the constructor will throw an @@ -22,6 +23,7 @@ export class MatchPattern { */ constructor(matchPattern: string) { if (matchPattern === '') { + this.isAllUrls = true; this.protocolMatches = [...MatchPattern.PROTOCOLS]; this.hostnameMatch = '*'; this.pathnameMatch = '*'; @@ -44,6 +46,8 @@ export class MatchPattern { * Check if a URL is included in a pattern. */ includes(url: string | URL | Location): boolean { + if (this.isAllUrls) return true; + const u: URL = typeof url === 'string' ? new URL(url) : url instanceof Location ? new URL(url.href) : url;