diff --git a/index.ts b/index.ts index 389c866..0aab4d3 100644 --- a/index.ts +++ b/index.ts @@ -27,5 +27,9 @@ function getRawRegex(matchPattern: string): string { } export function patternToRegex(...matchPatterns: readonly string[]): RegExp { + if (matchPatterns.includes('')) { + return /^(https?|file|ftp):[/]+/; + } + return new RegExp(matchPatterns.map(getRawRegex).join('|')); } diff --git a/test.js b/test.js index ae43b61..38d0d74 100644 --- a/test.js +++ b/test.js @@ -47,6 +47,15 @@ map.set('*://mail.google.com/*', [ 'https://mail.google.com/foobar', ]); +map.set('', [ + 'http://mail.google.com/foo/baz/bar', + 'https://mail.google.com/foobar', + 'file:///foo/bar.html', + 'file:///foo', + 'http://bfred.it', + 'ftp://example.com', +]); + for (const [pattern, urls] of map) { test(macro, pattern, urls); }