File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -233,14 +233,25 @@ function format(f) {
233
233
var debugs = { } ;
234
234
var debugEnviron ;
235
235
236
+ const regExpSpecialChars = / [ | \\ { } ( ) [ \] ^ $ + ? . ] / g;
237
+
238
+ function stringToRegExp ( string ) {
239
+ // Escape special chars except wildcard.
240
+ string = string . replace ( regExpSpecialChars , '\\$&' ) ;
241
+ // Transform wildcard to "match anything"
242
+ string = string . replace ( / \* / g, '.*' ) ;
243
+ return new RegExp ( `^${ string } $` ) ;
244
+ }
245
+
236
246
function debuglog ( set ) {
237
247
if ( debugEnviron === undefined ) {
238
- debugEnviron = new Set (
239
- ( process . env . NODE_DEBUG || '' ) . split ( ',' ) . map ( ( s ) => s . toUpperCase ( ) ) ) ;
248
+ debugEnviron = Array . from ( new Set (
249
+ ( process . env . NODE_DEBUG || '' ) . split ( ',' ) . map ( ( s ) => s . toUpperCase ( ) ) ) ) ;
250
+ debugEnviron = debugEnviron . map ( stringToRegExp ) ;
240
251
}
241
252
set = set . toUpperCase ( ) ;
242
253
if ( ! debugs [ set ] ) {
243
- if ( debugEnviron . has ( set ) ) {
254
+ if ( debugEnviron . some ( ( name ) => name . test ( set ) ) ) {
244
255
var pid = process . pid ;
245
256
debugs [ set ] = function ( ) {
246
257
var msg = exports . format . apply ( exports , arguments ) ;
Original file line number Diff line number Diff line change @@ -43,6 +43,15 @@ function parent() {
43
43
test ( 'f$oo' , true , 'f$oo' ) ;
44
44
test ( 'f$oo' , false , 'f.oo' ) ;
45
45
test ( 'no-bar-at-all' , false , 'bar' ) ;
46
+
47
+ test ( 'test-abc' , true , 'test-abc' ) ;
48
+ test ( 'test-a' , false , 'test-abc' ) ;
49
+ test ( 'test-*' , true , 'test-abc' ) ;
50
+ test ( 'test-*c' , true , 'test-abc' ) ;
51
+ test ( 'test-*abc' , true , 'test-abc' ) ;
52
+ test ( 'abc-test' , true , 'abc-test' ) ;
53
+ test ( 'a*-test' , true , 'abc-test' ) ;
54
+ test ( '*-test' , true , 'abc-test' ) ;
46
55
}
47
56
48
57
function test ( environ , shouldWrite , section ) {
You can’t perform that action at this time.
0 commit comments