Skip to content

Commit

Permalink
fixed windows file URIs with leading slashes (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Apr 18, 2016
1 parent 383b478 commit 8d31cb7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
8 changes: 7 additions & 1 deletion npa.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ function parseUrl (res, arg, urlparse) {

case "file:":
res.type = "local"
res.spec = urlparse.pathname
if (isWindows && arg.match(/^file:\/\/\/?[a-z]:/i)) {
// Windows URIs usually parse all wrong, so we just take matters
// into our own hands, in this case.
res.spec = arg.replace(/^file:\/\/\/?/i, '')
} else {
res.spec = urlparse.pathname
}
break

default:
Expand Down
32 changes: 32 additions & 0 deletions test/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,38 @@ var cases = {
spec: path.resolve("C:\\x\\y\\z"),
type: "local"
},
"foo@file:///C:\\x\\y\\z": {
raw: "foo@file:///C:\\x\\y\\z",
scope: null,
name: "foo",
rawSpec: "file:///C:\\x\\y\\z",
spec: path.resolve("C:\\x\\y\\z"),
type: "local"
},
"foo@file://C:\\x\\y\\z": {
raw: "foo@file://C:\\x\\y\\z",
scope: null,
name: "foo",
rawSpec: "file://C:\\x\\y\\z",
spec: path.resolve("C:\\x\\y\\z"),
type: "local"
},
"file:///C:\\x\\y\\z": {
raw: "file:///C:\\x\\y\\z",
scope: null,
name: null,
rawSpec: "file:///C:\\x\\y\\z",
spec: path.resolve("C:\\x\\y\\z"),
type: "local"
},
"file://C:\\x\\y\\z": {
raw: "file://C:\\x\\y\\z",
scope: null,
name: null,
rawSpec: "file://C:\\x\\y\\z",
spec: path.resolve("C:\\x\\y\\z"),
type: "local"
},
"foo@/foo/bar/baz": {
raw: "foo@/foo/bar/baz",
scope: null,
Expand Down

0 comments on commit 8d31cb7

Please sign in to comment.