Skip to content

Commit

Permalink
Fix last corner cases for path.normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
elvisvoer committed Feb 13, 2024
1 parent e2eda3d commit 4b7f403
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/b-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@ const posix = {

const handleFragment = () => {
if (dots === 2) {
fragments.pop();
if (fragments.length && fragments[fragments.length - 1] !== "..") {
// navigate up but don't pop an existing ".."
fragments.pop();
} else if (absolute) {
// top reached and absolute path
fragments.push(posix.sep);
} else {
// top reached and relative path
fragments.push("..");
}
}

if (word.length) {
Expand Down Expand Up @@ -146,7 +155,11 @@ const posix = {
handleFragment();

if (fragments.length === 0) {
return absolute ? posix.sep : ".";
if (absolute) {
return posix.sep;
}

return hasTrailingSep ? "./" : ".";
}

let result = fragments.join(posix.sep);
Expand Down

0 comments on commit 4b7f403

Please sign in to comment.