From 97e7f639061ea9d034b4cb7e85e02275c882f2e2 Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Wed, 7 Sep 2016 19:39:25 +0100 Subject: [PATCH 1/3] feat: short-circuit normalization if UNC --- lib/normalize.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/normalize.js b/lib/normalize.js index 04726d0..7606020 100644 --- a/lib/normalize.js +++ b/lib/normalize.js @@ -1,3 +1,4 @@ +var doubleSlackUNCRegExp = /^\\\\/; var doubleSlashWinRegExp = /\\+/g; var doubleSlashNixRegExp = /\/+/g; var currentDirectoryWinMiddleRegExp = /\\(\.\\)+/; @@ -34,5 +35,9 @@ module.exports = function normalize(path) { path = path.replace(parentDirectoryNixEndRegExp2, ""); path = path.replace(parentDirectoryNixEndRegExp3, "/"); + if (doubleSlackUNCRegExp.test(path)) { + return path; + } + return path.replace(doubleSlashWinRegExp, "\\").replace(doubleSlashNixRegExp, "/"); }; \ No newline at end of file From 5f318767b001dd0733e24dae8e39032eec605b2d Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Wed, 7 Sep 2016 19:39:50 +0100 Subject: [PATCH 2/3] feat: make pathToArray handle UNC --- lib/MemoryFileSystem.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/MemoryFileSystem.js b/lib/MemoryFileSystem.js index abfe803..94d06ab 100644 --- a/lib/MemoryFileSystem.js +++ b/lib/MemoryFileSystem.js @@ -38,8 +38,16 @@ function isFile(item) { function pathToArray(path) { path = normalize(path); + + var UNC = /^\\\\/.test(path); var nix = /^\//.test(path); - if(!nix) { + + if(UNC) { + path = path.slice(2); + path = path.replace(/[\\\/]+/g, "\\"); + path = path.split(/[\\\/]/); + path[0] = '\\\\' + path[0]; + } else if(!nix) { if(!/^[A-Za-z]:/.test(path)) { throw new MemoryFileSystemError(errors.code.EINVAL, path); } From 6fb1ecec62e5f634cbcfb17413430882f7fb6278 Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Wed, 7 Sep 2016 19:40:04 +0100 Subject: [PATCH 3/3] test: add a test case for pathToArray UNC --- test/MemoryFileSystem.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/MemoryFileSystem.js b/test/MemoryFileSystem.js index d11d889..5fc4611 100644 --- a/test/MemoryFileSystem.js +++ b/test/MemoryFileSystem.js @@ -341,6 +341,7 @@ describe("pathToArray", function() { fs.pathToArray("/a/b/c").should.be.eql(["a", "b", "c"]); fs.pathToArray("C:/a/b").should.be.eql(["C:", "a", "b"]); fs.pathToArray("C:\\a\\b").should.be.eql(["C:", "a", "b"]); + fs.pathToArray("\\\\a\\b\\c").should.be.eql(["\\\\a", "b", "c"]); }); it("should fail on invalid paths", function() { (function() {