Skip to content

Commit d7eba50

Browse files
Uzlopakmarco-ippolito
authored andcommittedJun 17, 2024
util: improve isInsideNodeModules
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>
1 parent 918962d commit d7eba50

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
 

‎lib/internal/util.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const {
3535
SafeSet,
3636
SafeWeakMap,
3737
SafeWeakRef,
38+
StringPrototypeIncludes,
3839
StringPrototypeReplace,
3940
StringPrototypeToLowerCase,
4041
StringPrototypeToUpperCase,
@@ -473,7 +474,7 @@ function spliceOne(list, index) {
473474
list.pop();
474475
}
475476

476-
const kNodeModulesRE = /^(.*)[\\/]node_modules[\\/]/;
477+
const kNodeModulesRE = /^(?:.*)[\\/]node_modules[\\/]/;
477478

478479
let getStructuredStack;
479480

@@ -503,8 +504,12 @@ function isInsideNodeModules() {
503504
const filename = frame.getFileName();
504505
// If a filename does not start with / or contain \,
505506
// it's likely from Node.js core.
506-
if (RegExpPrototypeExec(/^\/|\\/, filename) === null)
507+
if (
508+
filename[0] !== '/' &&
509+
StringPrototypeIncludes(filename, '\\') === false
510+
) {
507511
continue;
512+
}
508513
return RegExpPrototypeExec(kNodeModulesRE, filename) !== null;
509514
}
510515
}

0 commit comments

Comments
 (0)
Please sign in to comment.