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

Commit

Permalink
Merge pull request #34 from david-mitchell/unc-fix
Browse files Browse the repository at this point in the history
Normalize UNC paths correctly.
  • Loading branch information
sokra authored Jun 1, 2017
2 parents 17644e3 + 510260a commit 4b96090
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ module.exports = function normalize(path) {
result.push(part);
absolutePathStart = 2;
} else if(sep) {
result.push(part[0]);
// UNC paths on Windows begin with a double backslash.
if (i === 1 && parts[0].length === 0 && part === "\\\\") {
result.push(part);
} else {
result.push(part[0]);
}
} else if(part === "..") {
switch(result.length) {
case 0:
Expand Down
1 change: 1 addition & 0 deletions test/MemoryFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ describe("normalize", function() {
fs.normalize("C:\\a\\b\\\c\\..\\..").should.be.eql("C:\\a");
fs.normalize("C:\\a\\b\\d\\..\\c\\..\\..").should.be.eql("C:\\a");
fs.normalize("C:\\a\\b\\d\\\\.\\\\.\\c\\.\\..").should.be.eql("C:\\a\\b\\d");
fs.normalize("\\\\remote-computer\\c$\\file").should.be.eql("\\\\remote-computer\\c$\\file");
});
});
describe("pathToArray", function() {
Expand Down

0 comments on commit 4b96090

Please sign in to comment.