diff --git a/lib/MemoryFileSystem.js b/lib/MemoryFileSystem.js index abfe803..79c9933 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); } diff --git a/lib/join.js b/lib/join.js index 149ce8a..050814a 100644 --- a/lib/join.js +++ b/lib/join.js @@ -1,6 +1,6 @@ var normalize = require("./normalize"); -var absoluteWinRegExp = /^[A-Z]:([\\\/]|$)/i; +var absoluteWinRegExp = /^(?:[A-Z]:([\\\/]|$))|(\\\\)/i; var absoluteNixRegExp = /^\//i; module.exports = function join(path, request) { diff --git a/lib/normalize.js b/lib/normalize.js index 04726d0..fffe743 100644 --- a/lib/normalize.js +++ b/lib/normalize.js @@ -1,4 +1,4 @@ -var doubleSlashWinRegExp = /\\+/g; +var doubleSlashWinRegExp = /(?!^)\\+/g;; var doubleSlashNixRegExp = /\/+/g; var currentDirectoryWinMiddleRegExp = /\\(\.\\)+/; var currentDirectoryWinEndRegExp = /\\\.$/; @@ -34,5 +34,7 @@ module.exports = function normalize(path) { path = path.replace(parentDirectoryNixEndRegExp2, ""); path = path.replace(parentDirectoryNixEndRegExp3, "/"); - return path.replace(doubleSlashWinRegExp, "\\").replace(doubleSlashNixRegExp, "/"); -}; \ No newline at end of file + path = path.replace(doubleSlashWinRegExp, "\\").replace(doubleSlashNixRegExp, "/"); + + return path; +}; diff --git a/test/MemoryFileSystem.js b/test/MemoryFileSystem.js index d11d889..52eddd2 100644 --- a/test/MemoryFileSystem.js +++ b/test/MemoryFileSystem.js @@ -333,6 +333,8 @@ 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("\\\\a\\\\b").should.be.eql("\\\\a\\b"); + fs.normalize("\\\\a\\\\b\\..\\c").should.be.eql("\\\\a\\c"); }); }); describe("pathToArray", function() { @@ -341,6 +343,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() { @@ -363,6 +366,7 @@ describe("join", function() { fs.join("C:\\", "a\\b").should.be.eql("C:\\a\\b"); fs.join("C:/a/b", "./../c/d").should.be.eql("C:\\a\\c\\d"); fs.join("C:\\a\\b", "./../c/d").should.be.eql("C:\\a\\c\\d"); + fs.join("\\\\a\\b\\..\\c\\d\\..").should.be.eql("\\\\a\\c"); }); it("should join paths (weird cases)", function() { var fs = new MemoryFileSystem();