Skip to content

Commit e52523d

Browse files
kamilogorekHazAT
authored andcommitted
fix: Dont filter captured messages when they have no stacktraces (#1549)
1 parent bbacaee commit e52523d

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

packages/browser/src/integrations/inboundfilters.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class InboundFilters implements Integration {
8383
return false;
8484
}
8585
const url = this.getEventFilterUrl(event);
86-
return this.blacklistUrls.some(pattern => this.isMatchingPattern(url, pattern));
86+
return !url ? false : this.blacklistUrls.some(pattern => this.isMatchingPattern(url, pattern));
8787
}
8888

8989
/** JSDoc */
@@ -93,7 +93,7 @@ export class InboundFilters implements Integration {
9393
return true;
9494
}
9595
const url = this.getEventFilterUrl(event);
96-
return this.whitelistUrls.some(pattern => this.isMatchingPattern(url, pattern));
96+
return !url ? true : this.whitelistUrls.some(pattern => this.isMatchingPattern(url, pattern));
9797
}
9898

9999
/** JSDoc */
@@ -140,7 +140,7 @@ export class InboundFilters implements Integration {
140140
}
141141

142142
/** JSDoc */
143-
private getEventFilterUrl(event: SentryEvent): string {
143+
private getEventFilterUrl(event: SentryEvent): string | null {
144144
const evt = event as any;
145145

146146
try {
@@ -149,11 +149,11 @@ export class InboundFilters implements Integration {
149149
} else if (evt.exception) {
150150
return evt.exception.values[0].stacktrace.frames[0].filename;
151151
} else {
152-
return '';
152+
return null;
153153
}
154154
} catch (oO) {
155155
logger.error(`Cannot extract url for event ${getEventDescription(event)}`);
156-
return '';
156+
return null;
157157
}
158158
}
159159
}

packages/browser/test/integrations/inboundfilters.test.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ describe('InboundFilters', () => {
160160

161161
describe('blacklistUrls/whitelistUrls', () => {
162162
const messageEvent = {
163+
message: 'wat',
163164
stacktrace: {
164165
frames: [
165166
{
@@ -195,6 +196,23 @@ describe('InboundFilters', () => {
195196
expect(inboundFilters.isWhitelistedUrl(messageEvent)).equal(true);
196197
});
197198

199+
it('should not filter captured messages with no stacktraces', () => {
200+
inboundFilters.install({
201+
blacklistUrls: ['https://awesome-analytics.io'],
202+
whitelistUrls: ['https://awesome-analytics.io'],
203+
});
204+
expect(
205+
inboundFilters.isBlacklistedUrl({
206+
message: 'any',
207+
}),
208+
).equal(false);
209+
expect(
210+
inboundFilters.isWhitelistedUrl({
211+
message: 'any',
212+
}),
213+
).equal(true);
214+
});
215+
198216
it('should filter captured exception based on its stack trace using string filter', () => {
199217
inboundFilters.install({
200218
blacklistUrls: ['https://awesome-analytics.io'],
@@ -231,7 +249,7 @@ describe('InboundFilters', () => {
231249
expect(inboundFilters.isWhitelistedUrl(exceptionEvent)).equal(true);
232250
});
233251

234-
it('should not fail with malformed event event and default to false', () => {
252+
it('should not fail with malformed event event and default to false for isBlacklistedUrl and true for isWhitelistedUrl', () => {
235253
const malformedEvent = {
236254
stacktrace: {
237255
frames: undefined,
@@ -242,7 +260,7 @@ describe('InboundFilters', () => {
242260
whitelistUrls: ['https://awesome-analytics.io'],
243261
});
244262
expect(inboundFilters.isBlacklistedUrl(malformedEvent)).equal(false);
245-
expect(inboundFilters.isWhitelistedUrl(malformedEvent)).equal(false);
263+
expect(inboundFilters.isWhitelistedUrl(malformedEvent)).equal(true);
246264
});
247265
});
248266
});

0 commit comments

Comments
 (0)