Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 90cce6e

Browse filesBrowse files
HBSPStargos
authored andcommitted
path: remove repetitive conditional operator in posix.resolve
PR-URL: #54835 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 284db53 commit 90cce6e
Copy full SHA for 90cce6e

File tree

Expand file treeCollapse file tree

1 file changed

+9
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-2
lines changed
Open diff view settings
Collapse file

‎lib/path.js‎

Copy file name to clipboardExpand all lines: lib/path.js
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,8 +1163,8 @@ const posix = {
11631163
let resolvedPath = '';
11641164
let resolvedAbsolute = false;
11651165

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

11701170
// Skip empty entries
@@ -1177,6 +1177,13 @@ const posix = {
11771177
StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;
11781178
}
11791179

1180+
if (!resolvedAbsolute) {
1181+
const cwd = posixCwd();
1182+
resolvedPath = `${cwd}/${resolvedPath}`;
1183+
resolvedAbsolute =
1184+
StringPrototypeCharCodeAt(cwd, 0) === CHAR_FORWARD_SLASH;
1185+
}
1186+
11801187
// At this point the path should be resolved to a full absolute path, but
11811188
// handle relative paths to be safe (might happen when process.cwd() fails)
11821189

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.