Skip to content

Commit

Permalink
Merge 6fb1ece into 0a12b5c
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Sep 7, 2016
2 parents 0a12b5c + 6fb1ece commit 0a36786
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/MemoryFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/normalize.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var doubleSlackUNCRegExp = /^\\\\/;
var doubleSlashWinRegExp = /\\+/g;
var doubleSlashNixRegExp = /\/+/g;
var currentDirectoryWinMiddleRegExp = /\\(\.\\)+/;
Expand Down Expand Up @@ -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, "/");
};
1 change: 1 addition & 0 deletions test/MemoryFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 0a36786

Please sign in to comment.