GeezerVison is showing github.com — util: improve `isInsideNodeModules` · nodejs/node@a42b93b
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/util.js +7-2Lines changed: 7 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -35,6 +35,7 @@ const { |
35 | 35 | SafeSet, |
36 | 36 | SafeWeakMap, |
37 | 37 | SafeWeakRef, |
| 38 | + StringPrototypeIncludes, |
38 | 39 | StringPrototypeReplace, |
39 | 40 | StringPrototypeToLowerCase, |
40 | 41 | StringPrototypeToUpperCase, |
@@ -476,7 +477,7 @@ function spliceOne(list, index) { |
476 | 477 | list.pop(); |
477 | 478 | } |
478 | 479 |
|
479 | | -const kNodeModulesRE = /^(.*)[\\/]node_modules[\\/]/; |
| 480 | +const kNodeModulesRE = /^(?:.*)[\\/]node_modules[\\/]/; |
480 | 481 |
|
481 | 482 | let getStructuredStack; |
482 | 483 |
|
@@ -506,8 +507,12 @@ function isInsideNodeModules() { |
506 | 507 | const filename = frame.getFileName(); |
507 | 508 | // If a filename does not start with / or contain \, |
508 | 509 | // it's likely from Node.js core. |
509 | | - if (RegExpPrototypeExec(/^\/|\\/, filename) === null) |
| 510 | + if ( |
| 511 | + filename[0] !== '/' && |
| 512 | + StringPrototypeIncludes(filename, '\\') === false |
| 513 | + ) { |
510 | 514 | continue; |
| 515 | + } |
511 | 516 | return RegExpPrototypeExec(kNodeModulesRE, filename) !== null; |
512 | 517 | } |
513 | 518 | } |
|