From 510260a1f4eccb92977010b73d227b7f1c7d68a7 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Thu, 29 Dec 2016 11:30:39 -0800 Subject: [PATCH] Normalize UNC paths correctly. --- lib/normalize.js | 7 ++++++- test/MemoryFileSystem.js | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/normalize.js b/lib/normalize.js index aa8a013..48659fe 100644 --- a/lib/normalize.js +++ b/lib/normalize.js @@ -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: diff --git a/test/MemoryFileSystem.js b/test/MemoryFileSystem.js index af527d7..573c8ed 100644 --- a/test/MemoryFileSystem.js +++ b/test/MemoryFileSystem.js @@ -355,6 +355,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() {