diff --git a/lib/internal/util/debuglog.js b/lib/internal/util/debuglog.js index 06a4f8a2398555..c8d8178fdd1617 100644 --- a/lib/internal/util/debuglog.js +++ b/lib/internal/util/debuglog.js @@ -6,6 +6,7 @@ const { NumberPrototypeToFixed, ObjectDefineProperty, RegExp, + RegExpEscape, RegExpPrototypeExec, SafeArrayIterator, SafeMap, @@ -33,9 +34,9 @@ function initializeDebugEnv(debugEnv) { debugImpls = { __proto__: null }; if (debugEnv) { // This is run before any user code, it's OK not to use primordials. - debugEnv = debugEnv.replace(/[|\\{}()[\]^$+?.]/g, '\\$&') - .replaceAll('*', '.*') - .replaceAll(',', '$|^'); + debugEnv = RegExpEscape(debugEnv) + .replaceAll(RegExpEscape('*'), '[^.]*') + .replaceAll(RegExpEscape(','), '$|^'); const debugEnvRegex = new RegExp(`^${debugEnv}$`, 'i'); testEnabled = (str) => RegExpPrototypeExec(debugEnvRegex, str) !== null; } else {