Skip to content

Commit

Permalink
Fix local file
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepzh committed Feb 24, 2023
1 parent cf17e74 commit dc05df5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/util/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')
Expand Down
2 changes: 1 addition & 1 deletion test/util/pattern.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit dc05df5

Please sign in to comment.