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

Commit 0015f9a

Browse files
committed
fix: handle "./.." case
Previously, "./../a" was incorrectly transformed to "a". Paths of that form are sometimes seen by the webpack AliasPlugin.
1 parent 79a02a6 commit 0015f9a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/normalize.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ module.exports = function normalize(path) {
2525
// i. e. "a/../b/c" => "b/c"
2626
// i. e. "/../b/c" => "/b/c"
2727
// i. e. "C:\..\a\b\c" => "C:\a\b\c"
28-
i++;
29-
sep = !sep;
30-
result.length = absolutePathStart;
28+
if (result[0] !== ".") {
29+
i++;
30+
sep = !sep;
31+
result.length = absolutePathStart;
32+
} else {
33+
result.length = 0;
34+
result.push(part);
35+
}
3136
break;
3237
case 4:
3338
// i. e. "a/b/.." => "a"
@@ -80,7 +85,7 @@ module.exports = function normalize(path) {
8085
result.push(part);
8186
}
8287
}
83-
if(result.length === 1 && /^[A-Za-z]:$/.test(result))
88+
if(result.length === 1 && /^[A-Za-z]:$/.test(result[0]))
8489
return result[0] + "\\";
8590
return result.join("");
8691
};

test/MemoryFileSystem.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ describe("normalize", function() {
355355
fs.normalize("C:\\a\\b\\\c\\..\\..").should.be.eql("C:\\a");
356356
fs.normalize("C:\\a\\b\\d\\..\\c\\..\\..").should.be.eql("C:\\a");
357357
fs.normalize("C:\\a\\b\\d\\\\.\\\\.\\c\\.\\..").should.be.eql("C:\\a\\b\\d");
358+
fs.normalize("./../a").should.be.eql("../a");
359+
fs.normalize("/a/./../b").should.be.eql("/b");
360+
fs.normalize("/./../b").should.be.eql("/b");
361+
fs.normalize("C:\\.\\..\\a").should.be.eql("C:\\a");
362+
fs.normalize("C:\\a\\.\\..\\b").should.be.eql("C:\\b");
358363
});
359364
});
360365
describe("pathToArray", function() {

0 commit comments

Comments
 (0)