Skip to content

fix(nextjs): Handle braces in stack frame URLs #7900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/browser/src/stack-parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function createFrame(filename: string, func: string, lineno?: number, colno?: nu

// Chromium based browsers: Chrome, Brave, new Opera, new Edge
const chromeRegex =
/^\s*at (?:(.*\).*?|.*?) ?\((?:address at )?)?(?:async )?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
/^\s*at (?:(.+?\)(?: \[.+\])?|.*?) ?\((?:address at )?)?(?:async )?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
const chromeEvalRegex = /\((\S*)(?::(\d+))(?::(\d+))\)/;

const chrome: StackLineParserFn = line => {
Expand Down
35 changes: 35 additions & 0 deletions packages/browser/test/unit/tracekit/chromium.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,41 @@ describe('Tracekit - Chrome Tests', () => {
});
});

it('handles braces in urls', () => {
const CHROME_BRACES_URL = {
message: 'bad',
name: 'Error',
stack: `Error: bad
at something (http://localhost:5000/(some)/(thing)/index.html:20:16)
at more (http://localhost:5000/(some)/(thing)/index.html:25:7)`,
};

const ex = exceptionFromError(parser, CHROME_BRACES_URL);

expect(ex).toEqual({
value: 'bad',
type: 'Error',
stacktrace: {
frames: [
{
filename: 'http://localhost:5000/(some)/(thing)/index.html',
function: 'more',
lineno: 25,
colno: 7,
in_app: true,
},
{
filename: 'http://localhost:5000/(some)/(thing)/index.html',
function: 'something',
lineno: 20,
colno: 16,
in_app: true,
},
],
},
});
});

it('should drop frames that are over 1kb', () => {
const LONG_STR = 'A'.repeat(1040);

Expand Down