Skip to content

Commit e5a6e72

Browse files
gregorylegarecbenvinegar
authored andcommitted
Prevent to throw error when crumb.data.url is undefined (#1018)
1 parent d88422c commit e5a6e72

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/raven.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ Raven.prototype = {
13911391
data = objectMerge({}, crumb.data);
13921392
for (var j = 0; j < urlProps.length; ++j) {
13931393
urlProp = urlProps[j];
1394-
if (data.hasOwnProperty(urlProp)) {
1394+
if (data.hasOwnProperty(urlProp) && data[urlProp]) {
13951395
data[urlProp] = truncate(data[urlProp], this._globalOptions.maxUrlLength);
13961396
}
13971397
}

test/raven.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,31 @@ describe('globals', function() {
13981398
});
13991399
});
14001400

1401+
it('should not throw error when url in breadcrumb is undefined', function() {
1402+
this.sinon.stub(Raven, 'isSetup').returns(true);
1403+
this.sinon.stub(Raven, '_makeRequest');
1404+
this.sinon.stub(Raven, '_getHttpData').returns({
1405+
url: 'http://localhost/?a=b',
1406+
headers: {'User-Agent': 'lolbrowser'}
1407+
});
1408+
1409+
Raven._globalProject = '2';
1410+
Raven._globalOptions = {
1411+
logger: 'javascript',
1412+
maxMessageLength: 100
1413+
};
1414+
Raven._globalOptions.maxUrlLength = 35;
1415+
1416+
var obj = {method: 'POST', url: undefined};
1417+
// Do not freeze crumb data
1418+
1419+
Raven._breadcrumbs = [{type: 'request', timestamp: 0.1, data: obj}];
1420+
1421+
assert.doesNotThrow(function() {
1422+
Raven._send({message: 'bar'});
1423+
}, TypeError)
1424+
});
1425+
14011426
});
14021427

14031428
describe('makeRequest', function() {

0 commit comments

Comments
 (0)