-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: strip absolute paths more comprehensively
- Loading branch information
Showing
6 changed files
with
57 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// unix absolute paths are also absolute on win32, so we use this for both | ||
const { isAbsolute, parse } = require('path').win32 | ||
|
||
// returns [root, stripped] | ||
module.exports = path => { | ||
let r = '' | ||
while (isAbsolute(path)) { | ||
// windows will think that //x/y/z has a "root" of //x/y/ | ||
const root = path.charAt(0) === '/' ? '/' : parse(path).root | ||
path = path.substr(root.length) | ||
r += root | ||
} | ||
return [r, path] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const t = require('tap') | ||
const stripAbsolutePath = require('../lib/strip-absolute-path.js') | ||
|
||
const cases = { | ||
'/': ['/', ''], | ||
'////': ['////', ''], | ||
'c:///a/b/c': ['c:///', 'a/b/c'], | ||
'\\\\foo\\bar\\baz': ['\\\\foo\\bar\\', 'baz'], | ||
'//foo//bar//baz': ['//', 'foo//bar//baz'], | ||
'c:\\c:\\c:\\c:\\\\d:\\e/f/g': ['c:\\c:\\c:\\c:\\\\d:\\', 'e/f/g'], | ||
} | ||
|
||
for (const [input, [root, stripped]] of Object.entries(cases)) | ||
t.strictSame(stripAbsolutePath(input), [root, stripped], input) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters