Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: improve isInsideNodeModules #52147

Merged
merged 1 commit into from
May 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -476,7 +477,7 @@ function spliceOne(list, index) {
list.pop();
}

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

let getStructuredStack;

Expand Down Expand Up @@ -506,8 +507,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only applies to Windows right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this PR is already old but afaik it was effecting linux too

) {
continue;
}
return RegExpPrototypeExec(kNodeModulesRE, filename) !== null;
}
}
Expand Down