Skip to content

Commit 45692f4

Browse files
authored
fix(integrations): Handle lower-case prefix windows paths in RewriteFrames (#7506)
1 parent b6f03bf commit 45692f4

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

packages/integrations/src/rewriteframes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ export class RewriteFrames implements Integration {
7272
return frame;
7373
}
7474
// Check if the frame filename begins with `/` or a Windows-style prefix such as `C:\`
75-
const isWindowsFrame = /^[A-Z]:\\/.test(frame.filename);
75+
const isWindowsFrame = /^[a-zA-Z]:\\/.test(frame.filename);
7676
const startsWithSlash = /^\//.test(frame.filename);
7777
if (isWindowsFrame || startsWithSlash) {
7878
const filename = isWindowsFrame
7979
? frame.filename
80-
.replace(/^[A-Z]:/, '') // remove Windows-style prefix
80+
.replace(/^[a-zA-Z]:/, '') // remove Windows-style prefix
8181
.replace(/\\/g, '/') // replace all `\\` instances with `/`
8282
: frame.filename;
8383
const base = this._root ? relative(this._root, filename) : basename(filename);

packages/integrations/test/rewriteframes.test.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ let rewriteFrames: RewriteFrames;
66
let exceptionEvent: Event;
77
let exceptionWithoutStackTrace: Event;
88
let windowsExceptionEvent: Event;
9+
let windowsLowerCaseExceptionEvent: Event;
910
let multipleStacktracesEvent: Event;
1011

1112
describe('RewriteFrames', () => {
@@ -32,6 +33,17 @@ describe('RewriteFrames', () => {
3233
],
3334
},
3435
};
36+
windowsLowerCaseExceptionEvent = {
37+
exception: {
38+
values: [
39+
{
40+
stacktrace: {
41+
frames: [{ filename: 'c:\\www\\src\\app\\file1.js' }, { filename: 'c:\\www\\src\\app\\file2.js' }],
42+
},
43+
},
44+
],
45+
},
46+
};
3547
exceptionWithoutStackTrace = {
3648
exception: {
3749
values: [{}],
@@ -93,16 +105,22 @@ describe('RewriteFrames', () => {
93105
});
94106
});
95107

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

101-
it('transforms windowsExceptionEvent frames', () => {
113+
it('transforms windowsExceptionEvent frames (C:\\)', () => {
102114
const event = rewriteFrames.process(windowsExceptionEvent);
103115
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///file1.js');
104116
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///file2.js');
105117
});
118+
119+
it('transforms windowsExceptionEvent frames with lower-case prefix (c:\\)', () => {
120+
const event = rewriteFrames.process(windowsLowerCaseExceptionEvent);
121+
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///file1.js');
122+
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///file2.js');
123+
});
106124
});
107125

108126
describe('can use custom root to perform `relative` on filepaths', () => {
@@ -123,6 +141,12 @@ describe('RewriteFrames', () => {
123141
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///src/app/file1.js');
124142
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///src/app/file2.js');
125143
});
144+
145+
it('trasforms windowsExceptionEvent lower-case prefix frames', () => {
146+
const event = rewriteFrames.process(windowsLowerCaseExceptionEvent);
147+
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///src/app/file1.js');
148+
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///src/app/file2.js');
149+
});
126150
});
127151

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

0 commit comments

Comments
 (0)