Skip to content

Commit

Permalink
fix(integrations): Handle lower-case prefix windows paths in `Rewrite…
Browse files Browse the repository at this point in the history
…Frames` (#7506)
  • Loading branch information
Lms24 committed Mar 20, 2023
1 parent b6f03bf commit 45692f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
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

0 comments on commit 45692f4

Please sign in to comment.