File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1604,9 +1604,15 @@ function markNodeModules(ctx, line) {
16041604 tempLine += StringPrototypeSlice ( line , lastPos , moduleStart ) ;
16051605
16061606 let moduleEnd = StringPrototypeIndexOf ( line , separator , moduleStart ) ;
1607- if ( line [ moduleStart ] === '@' ) {
1607+ if ( moduleEnd === - 1 ) {
1608+ // No trailing separator: the module name runs to the end of the line.
1609+ moduleEnd = line . length ;
1610+ } else if ( line [ moduleStart ] === '@' ) {
16081611 // Namespaced modules have an extra slash: @namespace /package
16091612 moduleEnd = StringPrototypeIndexOf ( line , separator , moduleEnd + 1 ) ;
1613+ if ( moduleEnd === - 1 ) {
1614+ moduleEnd = line . length ;
1615+ }
16101616 }
16111617
16121618 const nodeModule = StringPrototypeSlice ( line , moduleStart , moduleEnd ) ;
Original file line number Diff line number Diff line change @@ -3418,6 +3418,21 @@ assert.strictEqual(
34183418 ) ;
34193419}
34203420
3421+ {
3422+ // A node_modules segment that is the last path component (no trailing
3423+ // separator after the module name) must not send markNodeModules into an
3424+ // infinite loop that exhausts the heap.
3425+ // https://github.com/nodejs/node/issues/64011
3426+ const err = new Error ( 'boom' ) ;
3427+ err . stack = 'Error: boom\n at /app/node_modules/foo.js:1:1' ;
3428+ const out = util . inspect ( err , { colors : true } ) ;
3429+ assert . strictEqual (
3430+ out ,
3431+ 'Error: boom\n' +
3432+ ' at /app/node_modules/\x1B[4mfoo.js:1:1\x1B[24m' ,
3433+ ) ;
3434+ }
3435+
34213436{
34223437 // Cross platform checks.
34233438 const err = new Error ( 'foo' ) ;
You can’t perform that action at this time.
0 commit comments