File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1876,9 +1876,15 @@ function markNodeModules(ctx, line) {
18761876 tempLine += StringPrototypeSlice ( line , lastPos , moduleStart ) ;
18771877
18781878 let moduleEnd = StringPrototypeIndexOf ( line , separator , moduleStart ) ;
1879- if ( line [ moduleStart ] === '@' ) {
1879+ if ( moduleEnd === - 1 ) {
1880+ // No trailing separator: the module name runs to the end of the line.
1881+ moduleEnd = line . length ;
1882+ } else if ( line [ moduleStart ] === '@' ) {
18801883 // Namespaced modules have an extra slash: @namespace /package
18811884 moduleEnd = StringPrototypeIndexOf ( line , separator , moduleEnd + 1 ) ;
1885+ if ( moduleEnd === - 1 ) {
1886+ moduleEnd = line . length ;
1887+ }
18821888 }
18831889
18841890 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