From 07783376dc0b2ff320e53cf6361d530387ba2b01 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 20 Mar 2024 23:00:51 +0100 Subject: [PATCH] util: improve isInsideNodeModules --- lib/internal/util.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/internal/util.js b/lib/internal/util.js index 226a57ddda55b3..9a01fc800d8074 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -35,6 +35,7 @@ const { SafeSet, SafeWeakMap, SafeWeakRef, + StringPrototypeIncludes, StringPrototypeReplace, StringPrototypeToLowerCase, StringPrototypeToUpperCase, @@ -476,7 +477,7 @@ function spliceOne(list, index) { list.pop(); } -const kNodeModulesRE = /^(.*)[\\/]node_modules[\\/]/; +const kNodeModulesRE = /^(?:.*)[\\/]node_modules[\\/]/; let getStructuredStack; @@ -506,8 +507,10 @@ 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, '\\')) { continue; + } return RegExpPrototypeExec(kNodeModulesRE, filename) !== null; } }