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

Commit 510260a

Browse files
author
David Mitchell
committed
Normalize UNC paths correctly.
1 parent 79a02a6 commit 510260a

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
@@ -355,6 +355,7 @@ describe("normalize", function() {
355355
fs.normalize("C:\\a\\b\\\c\\..\\..").should.be.eql("C:\\a");
356356
fs.normalize("C:\\a\\b\\d\\..\\c\\..\\..").should.be.eql("C:\\a");
357357
fs.normalize("C:\\a\\b\\d\\\\.\\\\.\\c\\.\\..").should.be.eql("C:\\a\\b\\d");
358+
fs.normalize("\\\\remote-computer\\c$\\file").should.be.eql("\\\\remote-computer\\c$\\file");
358359
});
359360
});
360361
describe("pathToArray", function() {

0 commit comments

Comments
 (0)