Skip to content
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

fix(integrations): Handle lower-case prefix windows paths in RewriteFrames #7506

Merged
merged 1 commit into from
Mar 20, 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
4 changes: 2 additions & 2 deletions packages/integrations/src/rewriteframes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ export class RewriteFrames implements Integration {
return frame;
}
// Check if the frame filename begins with `/` or a Windows-style prefix such as `C:\`
const isWindowsFrame = /^[A-Z]:\\/.test(frame.filename);
const isWindowsFrame = /^[a-zA-Z]:\\/.test(frame.filename);
const startsWithSlash = /^\//.test(frame.filename);
if (isWindowsFrame || startsWithSlash) {
const filename = isWindowsFrame
? frame.filename
.replace(/^[A-Z]:/, '') // remove Windows-style prefix
.replace(/^[a-zA-Z]:/, '') // remove Windows-style prefix
.replace(/\\/g, '/') // replace all `\\` instances with `/`
: frame.filename;
const base = this._root ? relative(this._root, filename) : basename(filename);
Expand Down
28 changes: 26 additions & 2 deletions packages/integrations/test/rewriteframes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let rewriteFrames: RewriteFrames;
let exceptionEvent: Event;
let exceptionWithoutStackTrace: Event;
let windowsExceptionEvent: Event;
let windowsLowerCaseExceptionEvent: Event;
let multipleStacktracesEvent: Event;

describe('RewriteFrames', () => {
Expand All @@ -32,6 +33,17 @@ describe('RewriteFrames', () => {
],
},
};
windowsLowerCaseExceptionEvent = {
exception: {
values: [
{
stacktrace: {
frames: [{ filename: 'c:\\www\\src\\app\\file1.js' }, { filename: 'c:\\www\\src\\app\\file2.js' }],
},
},
],
},
};
exceptionWithoutStackTrace = {
exception: {
values: [{}],
Expand Down Expand Up @@ -93,16 +105,22 @@ describe('RewriteFrames', () => {
});
});

describe('default iteratee appends basename to `app:///` if frame starts with `C:\\`', () => {
describe('default iteratee appends basename to `app:///` if frame starts with Windows path prefix', () => {
beforeEach(() => {
rewriteFrames = new RewriteFrames();
});

it('transforms windowsExceptionEvent frames', () => {
it('transforms windowsExceptionEvent frames (C:\\)', () => {
const event = rewriteFrames.process(windowsExceptionEvent);
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///file1.js');
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///file2.js');
});

it('transforms windowsExceptionEvent frames with lower-case prefix (c:\\)', () => {
const event = rewriteFrames.process(windowsLowerCaseExceptionEvent);
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///file1.js');
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///file2.js');
});
});

describe('can use custom root to perform `relative` on filepaths', () => {
Expand All @@ -123,6 +141,12 @@ describe('RewriteFrames', () => {
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///src/app/file1.js');
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///src/app/file2.js');
});

it('trasforms windowsExceptionEvent lower-case prefix frames', () => {
const event = rewriteFrames.process(windowsLowerCaseExceptionEvent);
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///src/app/file1.js');
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///src/app/file2.js');
});
});

describe('can use custom iteratee', () => {
Expand Down