Skip to content

Commit 66e9dc8

Browse files
committed
util: use RegExp.escape to better escape debugEnv
1 parent 00a8377 commit 66e9dc8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/internal/util/debuglog.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
NumberPrototypeToFixed,
77
ObjectDefineProperty,
88
RegExp,
9+
RegExpEscape,
910
RegExpPrototypeExec,
1011
SafeArrayIterator,
1112
SafeMap,
@@ -33,9 +34,9 @@ function initializeDebugEnv(debugEnv) {
3334
debugImpls = { __proto__: null };
3435
if (debugEnv) {
3536
// This is run before any user code, it's OK not to use primordials.
36-
debugEnv = debugEnv.replace(/[|\\{}()[\]^$+?.]/g, '\\$&')
37-
.replaceAll('*', '.*')
38-
.replaceAll(',', '$|^');
37+
debugEnv = RegExpEscape(debugEnv)
38+
.replaceAll(/(?<=[^\\]|^)\\\*/g, '[^.]*')
39+
.replaceAll(RegExpEscape(','), '$|^');
3940
const debugEnvRegex = new RegExp(`^${debugEnv}$`, 'i');
4041
testEnabled = (str) => RegExpPrototypeExec(debugEnvRegex, str) !== null;
4142
} else {

0 commit comments

Comments
 (0)