diff --git a/src/util/pattern.ts b/src/util/pattern.ts index ea3910ad..465bc4bb 100644 --- a/src/util/pattern.ts +++ b/src/util/pattern.ts @@ -74,9 +74,13 @@ export type HostInfo = { } export function extractHostname(url: string): HostInfo { + let fileHost = extractFileHost(url) + if (fileHost) { + return { host: fileHost, protocol: 'file' } + } + let host: string let protocol: string - const indexOfDoubleSlashes = url.indexOf("//") if (indexOfDoubleSlashes > -1) { const splits = url.split('/') diff --git a/test/util/pattern.test.ts b/test/util/pattern.test.ts index 64bc57df..a9399793 100644 --- a/test/util/pattern.test.ts +++ b/test/util/pattern.test.ts @@ -47,7 +47,7 @@ test("url", () => { expect(extractHostname('localhost:8087/?123=123')).toEqual({ host: 'localhost:8087', protocol: '' }) // the url of local files in firefox expect(extractHostname("file:///home/zhy/%E4%B8%8B%E8%BD%BD/%E6%88%91%E7%9A%84%E4%B8%8A%E7%BD%91%E6%97%B6%E9%97%B4_20220305_20220305.json")) - .toEqual({ host: "", protocol: "file" }) + .toEqual({ host: JSON_HOST, protocol: "file" }) }) test("homepage", () => {