Skip to content

Commit 1f01b70

Browse files
LucianBuzzothebigredgeek
authored andcommitted
Fix bug that would occure if process.env.DEBUG is a non-string value. (#444)
Connects to #443
1 parent 2f3ebf4 commit 1f01b70

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/debug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function enable(namespaces) {
141141
exports.names = [];
142142
exports.skips = [];
143143

144-
var split = (namespaces || '').split(/[\s,]+/);
144+
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
145145
var len = split.length;
146146

147147
for (var i = 0; i < len; i++) {

test/debug_spec.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ var chai
66
, debug
77
, sinon
88
, sinonChai;
9-
9+
1010
if (typeof module !== 'undefined') {
1111
chai = require('chai');
1212
expect = chai.expect;
13-
13+
1414
debug = require('../src/index');
1515
sinon = require('sinon');
1616
sinonChai = require("sinon-chai");
@@ -20,28 +20,32 @@ if (typeof module !== 'undefined') {
2020

2121
describe('debug', function () {
2222
var log = debug('test');
23-
23+
2424
log.log = sinon.stub();
25-
25+
2626
it('passes a basic sanity check', function () {
2727
expect(log('hello world')).to.not.throw;
2828
});
2929

30+
it('allows namespaces to be a non-string value', function () {
31+
expect(debug.enable(true)).to.not.throw;
32+
});
33+
3034
context('with log function', function () {
31-
35+
3236
beforeEach(function () {
3337
debug.enable('test');
3438
log = debug('test');
3539
});
36-
40+
3741
it('uses it', function () {
3842
log.log = sinon.stub();
3943
log('using custom log function');
4044

4145
expect(log.log).to.have.been.calledOnce;
4246
});
4347
});
44-
48+
4549
describe('custom functions', function () {
4650
var log;
4751

@@ -59,4 +63,5 @@ describe('debug', function () {
5963
});
6064
});
6165
});
66+
6267
});

0 commit comments

Comments
 (0)