Skip to content

Commit

Permalink
path: remove repetitive conditional operator in posix.resolve
Browse files Browse the repository at this point in the history
PR-URL: #54835
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
HBSPS authored and marco-ippolito committed Nov 17, 2024
1 parent a730cdb commit 3a682cc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -1164,8 +1164,8 @@ const posix = {
let resolvedPath = '';
let resolvedAbsolute = false;

for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
const path = i >= 0 ? args[i] : posixCwd();
for (let i = args.length - 1; i >= 0 && !resolvedAbsolute; i--) {
const path = args[i];
validateString(path, `paths[${i}]`);

// Skip empty entries
Expand All @@ -1178,6 +1178,13 @@ const posix = {
StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;
}

if (!resolvedAbsolute) {
const cwd = posixCwd();
resolvedPath = `${cwd}/${resolvedPath}`;
resolvedAbsolute =
StringPrototypeCharCodeAt(cwd, 0) === CHAR_FORWARD_SLASH;
}

// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)

Expand Down

0 comments on commit 3a682cc

Please sign in to comment.