Skip to content

Commit

Permalink
fix: handle file: when root directory begins with a special character
Browse files Browse the repository at this point in the history
PR-URL: #53
Credit: @MonochromeChameleon
Close: #53
Reviewed-by: @isaacs
  • Loading branch information
Hugh Greenish authored and isaacs committed Jun 2, 2021
1 parent d9d395f commit e8c4301
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion npa.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function fromFile (res, where) {

const spec = res.rawSpec.replace(/\\/g, '/')
.replace(/^file:[/]*([A-Za-z]:)/, '$1') // drive name paths on windows
.replace(/^file:(?:[/]*([~./]))?/, '$1')
.replace(/^file:(?:[/]*(~\/|\.*\/|[/]))?/, '$1')
if (/^~[/]/.test(spec)) {
// this is needed for windows and for file:~/foo/bar
res.fetchSpec = resolvePath(homedir(), spec.slice(2))
Expand Down
18 changes: 18 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,24 @@ require('tap').test('basic', function (t) {
raw: 'file:/~/path/to/foo',
},

'file:/~path/to/foo': {
name: null,
escapedName: null,
type: 'directory',
saveSpec: 'file:/~path/to/foo',
fetchSpec: '/~path/to/foo',
raw: 'file:/~path/to/foo',
},

'file:/.path/to/foo': {
name: null,
escapedName: null,
type: 'directory',
saveSpec: 'file:/.path/to/foo',
fetchSpec: '/.path/to/foo',
raw: 'file:/.path/to/foo',
},

'file:../path/to/foo': {
name: null,
escapedName: null,
Expand Down

0 comments on commit e8c4301

Please sign in to comment.