Skip to content

Commit f1c518d

Browse files
committed
Actually strip empty tags/extras
1 parent 66b9180 commit f1c518d

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/raven.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ function isString(what) {
362362
return typeof what === 'string';
363363
}
364364

365+
function isEmptyObject(what) {
366+
for (var k in what) return false;
367+
return true;
368+
}
369+
365370
function each(obj, callback) {
366371
var i, j;
367372

@@ -583,8 +588,8 @@ function send(data) {
583588
data.extra = arrayMerge(globalOptions.extra, data.extra);
584589

585590
// If there are no tags/extra, strip the key from the payload alltogther.
586-
if (!data.tags) delete data.tags;
587-
if (!data.extra) delete data.extra;
591+
if (isEmptyObject(data.tags)) delete data.tags;
592+
if (isEmptyObject(data.extra)) delete data.extra;
588593

589594
if (globalUser) {
590595
// sentry.interfaces.User

test/raven.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ describe('globals', function() {
102102
});
103103
});
104104

105+
describe('isEmptyObject', function() {
106+
it('should work as advertised', function() {
107+
assert.isTrue(isEmptyObject({}));
108+
assert.isFalse(isEmptyObject({foo: 1}));
109+
});
110+
});
111+
105112
describe('isSetup', function() {
106113
it('should return false with no JSON support', function() {
107114
globalServer = 'http://localhost/';
@@ -669,6 +676,38 @@ describe('globals', function() {
669676
lol: 'ibrokeit'
670677
}]);
671678
});
679+
680+
it('should strip empty tags/extra', function() {
681+
this.sinon.stub(window, 'isSetup').returns(true);
682+
this.sinon.stub(window, 'makeRequest');
683+
this.sinon.stub(window, 'getHttpData').returns({
684+
url: 'http://localhost/?a=b',
685+
headers: {'User-Agent': 'lolbrowser'}
686+
});
687+
688+
globalOptions = {
689+
projectId: 2,
690+
logger: 'javascript',
691+
site: 'THE BEST',
692+
tags: {},
693+
extra: {}
694+
};
695+
696+
send({foo: 'bar', tags: {}, extra: {}});
697+
assert.deepEqual(window.makeRequest.lastCall.args[0], {
698+
project: 2,
699+
logger: 'javascript',
700+
site: 'THE BEST',
701+
platform: 'javascript',
702+
request: {
703+
url: 'http://localhost/?a=b',
704+
headers: {
705+
'User-Agent': 'lolbrowser'
706+
}
707+
},
708+
foo: 'bar'
709+
});
710+
});
672711
});
673712

674713
describe('makeRequest', function() {

0 commit comments

Comments
 (0)