Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -1754,9 +1754,6 @@ Raven.prototype = {
};
}

// If there are no tags/extra, strip the key from the payload alltogther.
if (isEmptyObject(data.tags)) delete data.tags;

if (this._globalContext.user) {
// sentry.interfaces.User
data.user = this._globalContext.user;
Expand All @@ -1771,6 +1768,13 @@ Raven.prototype = {
// Include server_name if it's defined in globalOptions
if (globalOptions.serverName) data.server_name = globalOptions.serverName;

// Cleanup empty properties before sending them to the server
Object.keys(data).forEach(function(key) {
if (data[key] == null || data[key] === '' || isEmptyObject(data[key])) {
delete data[key];
}
});

if (isFunction(globalOptions.dataCallback)) {
data = globalOptions.dataCallback(data) || data;
}
Expand Down
7 changes: 7 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ function isFunction(what) {
return typeof what === 'function';
}

function isPlainObject(what) {
return Object.prototype.toString.call(what) === '[object Object]';
}

function isString(what) {
return Object.prototype.toString.call(what) === '[object String]';
}
Expand All @@ -43,6 +47,8 @@ function isArray(what) {
}

function isEmptyObject(what) {
if (!isPlainObject(what)) return false;

for (var _ in what) {
if (what.hasOwnProperty(_)) {
return false;
Expand Down Expand Up @@ -397,6 +403,7 @@ module.exports = {
isErrorEvent: isErrorEvent,
isUndefined: isUndefined,
isFunction: isFunction,
isPlainObject: isPlainObject,
isString: isString,
isArray: isArray,
isEmptyObject: isEmptyObject,
Expand Down
14 changes: 11 additions & 3 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ describe('globals', function() {
assert.isTrue(Raven._makeRequest.called);
});

it('should strip empty tags', function() {
it('should strip empty attributes', function() {
this.sinon.stub(Raven, 'isSetup').returns(true);
this.sinon.stub(Raven, '_makeRequest');
this.sinon.stub(Raven, '_getHttpData').returns({
Expand All @@ -1148,10 +1148,18 @@ describe('globals', function() {
projectId: 2,
logger: 'javascript',
maxMessageLength: 100,
tags: {}
tags: {},
extra: {}
};

Raven._send({message: 'bar', tags: {}, extra: {}});
Raven._send({
message: 'bar',
tags: {},
extra: {},
redundant: '',
attribute: null,
something: undefined
});
assert.deepEqual(Raven._makeRequest.lastCall.args[0].data, {
project: '2',
logger: 'javascript',
Expand Down
15 changes: 15 additions & 0 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var RavenConfigError = require('../src/configError');
var utils = require('../src/utils');
var isUndefined = utils.isUndefined;
var isFunction = utils.isFunction;
var isPlainObject = utils.isPlainObject;
var isString = utils.isString;
var isArray = utils.isArray;
var isObject = utils.isObject;
Expand Down Expand Up @@ -42,6 +43,20 @@ describe('utils', function() {
});
});

describe('isPlainObject', function() {
it('should do as advertised', function() {
assert.isTrue(isPlainObject({}));
assert.isTrue(isPlainObject({foo: 'bar'}));
assert.isTrue(isPlainObject(new Object()));
assert.isFalse(isPlainObject([]));
assert.isFalse(isPlainObject(undefined));
assert.isFalse(isPlainObject(null));
assert.isFalse(isPlainObject(1));
assert.isFalse(isPlainObject(''));
assert.isFalse(isPlainObject(function() {}));
});
});

describe('isString', function() {
it('should do as advertised', function() {
assert.isTrue(isString(''));
Expand Down