From 713e47a619f7490af7149c14e521c687355c56c7 Mon Sep 17 00:00:00 2001 From: Lucian Buzzo Date: Thu, 20 Apr 2017 11:44:38 +0100 Subject: [PATCH] Fix bug that would occure if process.env.DEBUG is a non-string value. Connects to #443 --- src/debug.js | 2 +- test/debug_spec.js | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/debug.js b/src/debug.js index d5d6d167..6a5e3fc9 100644 --- a/src/debug.js +++ b/src/debug.js @@ -141,7 +141,7 @@ function enable(namespaces) { exports.names = []; exports.skips = []; - var split = (namespaces || '').split(/[\s,]+/); + var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/); var len = split.length; for (var i = 0; i < len; i++) { diff --git a/test/debug_spec.js b/test/debug_spec.js index 4ab4d88d..142fbe79 100644 --- a/test/debug_spec.js +++ b/test/debug_spec.js @@ -6,11 +6,11 @@ var chai , debug , sinon , sinonChai; - + if (typeof module !== 'undefined') { chai = require('chai'); expect = chai.expect; - + debug = require('../src/index'); sinon = require('sinon'); sinonChai = require("sinon-chai"); @@ -20,20 +20,24 @@ if (typeof module !== 'undefined') { describe('debug', function () { var log = debug('test'); - + log.log = sinon.stub(); - + it('passes a basic sanity check', function () { expect(log('hello world')).to.not.throw; }); + it('allows namespaces to be a non-string value', function () { + expect(debug.enable(true)).to.not.throw; + }); + context('with log function', function () { - + beforeEach(function () { debug.enable('test'); log = debug('test'); }); - + it('uses it', function () { log.log = sinon.stub(); log('using custom log function'); @@ -41,7 +45,7 @@ describe('debug', function () { expect(log.log).to.have.been.calledOnce; }); }); - + describe('custom functions', function () { var log; @@ -59,4 +63,5 @@ describe('debug', function () { }); }); }); + });