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

Commit 8a15514

Browse files
authored
Merge pull request #33 from jbms/master
fix: handle "./.." case
2 parents cbf7387 + 6666525 commit 8a15514

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
@@ -33,9 +33,14 @@ module.exports = function normalize(path) {
3333
// i. e. "a/../b/c" => "b/c"
3434
// i. e. "/../b/c" => "/b/c"
3535
// i. e. "C:\..\a\b\c" => "C:\a\b\c"
36-
i += 1;
37-
sep = !sep;
38-
result.length = absolutePathStart;
36+
if (result[0] !== ".") {
37+
i += 1;
38+
sep = !sep;
39+
result.length = absolutePathStart;
40+
} else {
41+
result.length = 0;
42+
result.push(part);
43+
}
3944
break;
4045
case 4:
4146
// i. e. "a/b/.." => "a"
@@ -88,7 +93,7 @@ module.exports = function normalize(path) {
8893
result.push(part);
8994
}
9095
}
91-
if(result.length === 1 && /^[A-Za-z]:$/.test(result))
96+
if(result.length === 1 && /^[A-Za-z]:$/.test(result[0]))
9297
return result[0] + "\\";
9398
return result.join("");
9499
};

test/MemoryFileSystem.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,11 @@ describe("normalize", function() {
359359
fs.normalize("C:\\a\\b\\d\\..\\c\\..\\..").should.be.eql("C:\\a");
360360
fs.normalize("C:\\a\\b\\d\\\\.\\\\.\\c\\.\\..").should.be.eql("C:\\a\\b\\d");
361361
fs.normalize("\\\\remote-computer\\c$\\file").should.be.eql("\\\\remote-computer\\c$\\file");
362+
fs.normalize("./../a").should.be.eql("../a");
363+
fs.normalize("/a/./../b").should.be.eql("/b");
364+
fs.normalize("/./../b").should.be.eql("/b");
365+
fs.normalize("C:\\.\\..\\a").should.be.eql("C:\\a");
366+
fs.normalize("C:\\a\\.\\..\\b").should.be.eql("C:\\b");
362367
});
363368
});
364369
describe("pathToArray", function() {

0 commit comments

Comments
 (0)