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

Commit

Permalink
fix: handle "./.." case
Browse files Browse the repository at this point in the history
Previously, "./../a" was incorrectly transformed to "a".  Paths of
that form are sometimes seen by the webpack AliasPlugin.
  • Loading branch information
jbms committed Jan 20, 2017
1 parent 79a02a6 commit 0015f9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ module.exports = function normalize(path) {
// i. e. "a/../b/c" => "b/c"
// i. e. "/../b/c" => "/b/c"
// i. e. "C:\..\a\b\c" => "C:\a\b\c"
i++;
sep = !sep;
result.length = absolutePathStart;
if (result[0] !== ".") {
i++;
sep = !sep;
result.length = absolutePathStart;
} else {
result.length = 0;
result.push(part);
}
break;
case 4:
// i. e. "a/b/.." => "a"
Expand Down Expand Up @@ -80,7 +85,7 @@ module.exports = function normalize(path) {
result.push(part);
}
}
if(result.length === 1 && /^[A-Za-z]:$/.test(result))
if(result.length === 1 && /^[A-Za-z]:$/.test(result[0]))
return result[0] + "\\";
return result.join("");
};
5 changes: 5 additions & 0 deletions test/MemoryFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ 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").should.be.eql("../a");
fs.normalize("/a/./../b").should.be.eql("/b");
fs.normalize("/./../b").should.be.eql("/b");
fs.normalize("C:\\.\\..\\a").should.be.eql("C:\\a");
fs.normalize("C:\\a\\.\\..\\b").should.be.eql("C:\\b");
});
});
describe("pathToArray", function() {
Expand Down

0 comments on commit 0015f9a

Please sign in to comment.