Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Commit 4b96090

Browse files
authored
Merge pull request #34 from david-mitchell/unc-fix
Normalize UNC paths correctly.
2 parents 17644e3 + 510260a commit 4b96090

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/normalize.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ module.exports = function normalize(path) {
1010
result.push(part);
1111
absolutePathStart = 2;
1212
} else if(sep) {
13-
result.push(part[0]);
13+
// UNC paths on Windows begin with a double backslash.
14+
if (i === 1 && parts[0].length === 0 && part === "\\\\") {
15+
result.push(part);
16+
} else {
17+
result.push(part[0]);
18+
}
1419
} else if(part === "..") {
1520
switch(result.length) {
1621
case 0:

test/MemoryFileSystem.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ describe("normalize", function() {
358358
fs.normalize("C:\\a\\b\\\c\\..\\..").should.be.eql("C:\\a");
359359
fs.normalize("C:\\a\\b\\d\\..\\c\\..\\..").should.be.eql("C:\\a");
360360
fs.normalize("C:\\a\\b\\d\\\\.\\\\.\\c\\.\\..").should.be.eql("C:\\a\\b\\d");
361+
fs.normalize("\\\\remote-computer\\c$\\file").should.be.eql("\\\\remote-computer\\c$\\file");
361362
});
362363
});
363364
describe("pathToArray", function() {

0 commit comments

Comments
 (0)