Skip to content

Commit

Permalink
util: improve isInsideNodeModules
Browse files Browse the repository at this point in the history
PR-URL: #52147
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
Uzlopak authored and marco-ippolito committed Jun 17, 2024
1 parent 918962d commit d7eba50
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const {
SafeSet,
SafeWeakMap,
SafeWeakRef,
StringPrototypeIncludes,
StringPrototypeReplace,
StringPrototypeToLowerCase,
StringPrototypeToUpperCase,
Expand Down Expand Up @@ -473,7 +474,7 @@ function spliceOne(list, index) {
list.pop();
}

const kNodeModulesRE = /^(.*)[\\/]node_modules[\\/]/;
const kNodeModulesRE = /^(?:.*)[\\/]node_modules[\\/]/;

let getStructuredStack;

Expand Down Expand Up @@ -503,8 +504,12 @@ function isInsideNodeModules() {
const filename = frame.getFileName();
// If a filename does not start with / or contain \,
// it's likely from Node.js core.
if (RegExpPrototypeExec(/^\/|\\/, filename) === null)
if (
filename[0] !== '/' &&
StringPrototypeIncludes(filename, '\\') === false
) {
continue;
}
return RegExpPrototypeExec(kNodeModulesRE, filename) !== null;
}
}
Expand Down

0 comments on commit d7eba50

Please sign in to comment.