Skip to content

Commit d3d6f98

Browse files
authored
fix: use correct call url in ignore/whitelisturl calls (#1304)
1 parent a25aa97 commit d3d6f98

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/raven.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,14 @@ Raven.prototype = {
571571

572572
// stack[0] is `throw new Error(msg)` call itself, we are interested in the frame that was just before that, stack[1]
573573
var initialCall = isArray(stack.stack) && stack.stack[1];
574+
575+
// if stack[1] is `Raven.captureException`, it means that someone passed a string to it and we redirected that call
576+
// to be handled by `captureMessage`, thus `initialCall` is the 3rd one, not 2nd
577+
// initialCall => captureException(string) => captureMessage(string)
578+
if (initialCall && initialCall.func === 'Raven.captureException') {
579+
initialCall = stack.stack[2];
580+
}
581+
574582
var fileurl = (initialCall && initialCall.url) || '';
575583

576584
if (

test/raven.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,6 +3015,30 @@ describe('Raven (public API)', function() {
30153015
assert.isTrue(Raven._send.calledOnce);
30163016
});
30173017

3018+
it('should use 3rd frame from stack to get a fileurl if captureMessage was just a redirect from captureException', function() {
3019+
this.sinon.stub(Raven, '_send');
3020+
var TraceKitStub = this.sinon.stub(TraceKit, 'computeStackTrace');
3021+
TraceKitStub.returns({
3022+
stack: [
3023+
{url: 'http://example.com', func: 'Raven.captureMessage'},
3024+
{url: 'http://example.com', func: 'Raven.captureException'},
3025+
{url: '<anonymous>', func: '?'}
3026+
]
3027+
});
3028+
Raven._globalOptions.whitelistUrls = {
3029+
test: function() {
3030+
return false;
3031+
}
3032+
};
3033+
this.sinon.spy(Raven._globalOptions.whitelistUrls, 'test');
3034+
this.sinon.spy(Raven, 'captureMessage');
3035+
3036+
Raven.captureException('some string');
3037+
3038+
assert.isTrue(Raven.captureMessage.calledWith('some string'));
3039+
assert.isTrue(Raven._globalOptions.whitelistUrls.test.calledWith('<anonymous>'));
3040+
});
3041+
30183042
describe('synthetic traces', function() {
30193043
function assertSynthetic(frames) {
30203044
// Raven.captureMessage

0 commit comments

Comments
 (0)