Skip to content

Commit

Permalink
src: do not call path.back() when it is empty
Browse files Browse the repository at this point in the history
PR-URL: nodejs#55072
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
  • Loading branch information
zcbenz authored and louwers committed Nov 2, 2024
1 parent 340ebda commit 9738b35
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ std::string PathResolve(Environment* env,
for (int i = numArgs - 1; i >= -1 && !resolvedAbsolute; i--) {
const std::string& path = (i >= 0) ? std::string(paths[i]) : cwd;

if (static_cast<size_t>(i) == numArgs - 1 && path.back() == '/') {
slashCheck = true;
}

if (!path.empty()) {
if (static_cast<size_t>(i) == numArgs - 1 && path.back() == '/') {
slashCheck = true;
}

resolvedPath = std::string(path) + "/" + resolvedPath;

if (path.front() == '/') {
Expand Down

0 comments on commit 9738b35

Please sign in to comment.