Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 11 additions & 2 deletions packages/core/src/utils/node-stack-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ export function node(getModule?: GetModuleFn): StackLineParserFn {
filename = lineMatch[5];
}

const maybeFilename = filename ? _safeDecodeURI(filename) : undefined;
return {
filename: filename ? decodeURI(filename) : undefined,
module: getModule ? getModule(filename) : undefined,
filename: maybeFilename,
module: getModule?.(maybeFilename),
function: functionName,
lineno: _parseIntOrUndefined(lineMatch[3]),
colno: _parseIntOrUndefined(lineMatch[4]),
Expand Down Expand Up @@ -148,3 +149,11 @@ export function nodeStackLineParser(getModule?: GetModuleFn): StackLineParser {
function _parseIntOrUndefined(input: string | undefined): number | undefined {
return parseInt(input || '', 10) || undefined;
}

function _safeDecodeURI(filename: string): string | undefined {
try {
return decodeURI(filename);
} catch {
return undefined;
}
}
Comment thread
cursor[bot] marked this conversation as resolved.
17 changes: 17 additions & 0 deletions packages/core/test/lib/utils/stacktrace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,21 @@ describe('node', () => {

expect(node(input)).toEqual(expectedOutput);
});

it('returns undefined when decodeURI throws a URIError', () => {
const malformedFilename = '/path/to/%file%.js';
const input = `at myFunction (${malformedFilename}:10:5)`;

const result = node(input);

expect(result?.filename).toBeUndefined();
});
Comment thread
cursor[bot] marked this conversation as resolved.

it('decodes a valid percent-encoded filename', () => {
const input = 'at myFunction (/path/to/my%20file.js:10:5)';

const result = node(input);

expect(result?.filename).toBe('/path/to/my file.js');
});
});
Loading