Skip to content

Commit 509843e

Browse files
committed
Better handle if/when the dataCallback returns garbage
1 parent c687f95 commit 509843e

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/raven.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,12 @@ function send(data) {
725725
if (globalOptions.release) data.release = globalOptions.release;
726726

727727
if (isFunction(globalOptions.dataCallback)) {
728-
data = globalOptions.dataCallback(data);
728+
data = globalOptions.dataCallback(data) || data;
729+
}
730+
731+
// Why??????????
732+
if (!data || isEmptyObject(data)) {
733+
return;
729734
}
730735

731736
// Check if the request should be filtered or not

test/raven.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,39 @@ describe('globals', function() {
976976
}]);
977977
});
978978

979+
it('should ignore dataCallback if it does not return anything', function() {
980+
this.sinon.stub(window, 'isSetup').returns(true);
981+
this.sinon.stub(window, 'makeRequest');
982+
this.sinon.stub(window, 'getHttpData').returns({
983+
url: 'http://localhost/?a=b',
984+
headers: {'User-Agent': 'lolbrowser'}
985+
});
986+
987+
globalProject = '2';
988+
globalOptions = {
989+
logger: 'javascript',
990+
dataCallback: function() {
991+
return;
992+
}
993+
};
994+
995+
send({foo: 'bar'});
996+
assert.deepEqual(window.makeRequest.lastCall.args[0], {
997+
project: '2',
998+
logger: 'javascript',
999+
platform: 'javascript',
1000+
request: {
1001+
url: 'http://localhost/?a=b',
1002+
headers: {
1003+
'User-Agent': 'lolbrowser'
1004+
}
1005+
},
1006+
event_id: 'abc123',
1007+
foo: 'bar',
1008+
extra: {'session:duration': 100}
1009+
});
1010+
});
1011+
9791012
it('should strip empty tags', function() {
9801013
this.sinon.stub(window, 'isSetup').returns(true);
9811014
this.sinon.stub(window, 'makeRequest');

0 commit comments

Comments
 (0)