Skip to content

Commit

Permalink
allow whitelisting by var name
Browse files Browse the repository at this point in the history
Useful in cases when you do not know ahead of time what
the value of the global variable leak will be.
  • Loading branch information
aheckmann committed Sep 7, 2011
1 parent 09181e7 commit 4333332
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ exports.detect = function detect () {
Object.keys(global).forEach(function (key) {
var w = whitelist.length
, bad = true
, white

while (w--) if (global[key] === whitelist[w]) {
bad = false;
break;
while (w--) {
white = whitelist[w];
if (global[key] === white || 'string' === typeof white && key === white) {
bad = false;
break;
}
}

if (bad) ret.push(key);
Expand Down
9 changes: 8 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ exports['detect()'] = function () {
assert.equal("haha", gleak.detect()[0]);
}

exports['unknown values can be whitelisted by passing strings'] = function () {
ignoreme = 1;
assert.ok(~gleak.detect().indexOf('ignoreme'));
gleak.whitelist.push('ignoreme');
assert.ok(!~gleak.detect().indexOf('ignoreme'));
delete global.ignoreme;
}

exports['print()'] = function () {
var write = console.error;
var times = 0;
Expand All @@ -72,7 +80,6 @@ exports['print()'] = function () {
}

exports['test middleware'] = function (beforeExit) {

var called = false;
var req = {};
var res = { send: function (x) { assert.equal(x, 'yes'); called = true; }};
Expand Down

0 comments on commit 4333332

Please sign in to comment.