Skip to content

Commit 513e336

Browse files
committed
fix(node): Handle stack traces with data URI filenames
1 parent faada7c commit 513e336

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

packages/core/src/utils/node-stack-trace.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,17 @@ export function filenameIsInApp(filename: string, isNative: boolean = false): bo
5353
export function node(getModule?: GetModuleFn): StackLineParserFn {
5454
const FILENAME_MATCH = /^\s*[-]{4,}$/;
5555
const FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/;
56+
const DATA_URI_MATCH = /at (?:async )?(?:(.+?) \(data:(.+),)/;
5657

5758
// eslint-disable-next-line complexity
5859
return (line: string) => {
60+
const dataUriMatch = line.match(DATA_URI_MATCH);
61+
if (dataUriMatch) {
62+
return {
63+
filename: `<data:${dataUriMatch[2]}>`,
64+
function: dataUriMatch[1],
65+
}
66+
}
5967
const lineMatch = line.match(FULL_MATCH);
6068

6169
if (lineMatch) {

packages/core/src/utils/stacktrace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ export function createStackParser(...parsers: StackLineParser[]): StackParser {
2323
const lines = stack.split('\n');
2424

2525
for (let i = skipFirstLines; i < lines.length; i++) {
26-
const line = lines[i] as string;
26+
let line = lines[i] as string;
2727
// Ignore lines over 1kb as they are unlikely to be stack frames.
2828
// Many of the regular expressions use backtracking which results in run time that increases exponentially with
2929
// input size. Huge strings can result in hangs/Denial of Service:
3030
// https://github.com/getsentry/sentry-javascript/issues/2286
3131
if (line.length > 1024) {
32-
continue;
32+
line = line.slice(0, 1024);
3333
}
3434

3535
// https://github.com/getsentry/sentry-javascript/issues/5459

packages/core/test/lib/utils/stacktrace.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,4 +380,15 @@ describe('node', () => {
380380

381381
expect(node(input)).toEqual(expectedOutput);
382382
});
383+
384+
it('parses function name when filename is a data uri ', () => {
385+
const input = 'at dynamicFn (data:application/javascript,export function dynamicFn() { throw new Error(\'Error from data-uri module\');};:1:38)';
386+
387+
const expectedOutput = {
388+
function: 'dynamicFn',
389+
filename: '<data:application/javascript>',
390+
};
391+
392+
expect(node(input)).toEqual(expectedOutput);
393+
});
383394
});

0 commit comments

Comments
 (0)