Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion packages/core/src/utils/node-stack-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function node(getModule?: GetModuleFn): StackLineParserFn {
}

return {
filename: filename ? decodeURI(filename) : undefined,
filename: filename ? _safeDecodeURI(filename) : undefined,
module: getModule ? getModule(filename) : undefined,
Comment thread
sentry[bot] marked this conversation as resolved.
Outdated
function: functionName,
lineno: _parseIntOrUndefined(lineMatch[3]),
Expand Down Expand Up @@ -148,3 +148,11 @@ export function nodeStackLineParser(getModule?: GetModuleFn): StackLineParser {
function _parseIntOrUndefined(input: string | undefined): number | undefined {
return parseInt(input || '', 10) || undefined;
}

function _safeDecodeURI(filename: string): string {
try {
return decodeURI(filename);
} catch {
return filename;
}
}
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 the raw filename 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).toBe(malformedFilename);
});
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