Skip to content

Commit 184622d

Browse files
authored
fix(integrations): Handle windows paths with no prefix or backslash prefix in RewriteFrames (#7995)
Forward slashes are not allowed in Windows paths. This fix extends RewriteFrames to detect additional Windows-like paths and convert them to use forward slashes.
1 parent e0c3229 commit 184622d

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

packages/integrations/src/rewriteframes.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ export class RewriteFrames implements Integration {
7171
if (!frame.filename) {
7272
return frame;
7373
}
74-
// Check if the frame filename begins with `/` or a Windows-style prefix such as `C:\`
75-
const isWindowsFrame = /^[a-zA-Z]:\\/.test(frame.filename);
74+
// Determine if this is a Windows frame by checking for a Windows-style prefix such as `C:\`
75+
const isWindowsFrame =
76+
/^[a-zA-Z]:\\/.test(frame.filename) ||
77+
// or the presence of a backslash without a forward slash (which are not allowed on Windows)
78+
(frame.filename.includes('\\') && !frame.filename.includes('/'));
79+
// Check if the frame filename begins with `/`
7680
const startsWithSlash = /^\//.test(frame.filename);
7781
if (isWindowsFrame || startsWithSlash) {
7882
const filename = isWindowsFrame

packages/integrations/test/rewriteframes.test.ts

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ let exceptionEvent: Event;
77
let exceptionWithoutStackTrace: Event;
88
let windowsExceptionEvent: Event;
99
let windowsLowerCaseExceptionEvent: Event;
10+
let windowsExceptionEventWithoutPrefix: Event;
11+
let windowsExceptionEventWithBackslashPrefix: Event;
1012
let multipleStacktracesEvent: Event;
1113

1214
describe('RewriteFrames', () => {
@@ -44,6 +46,28 @@ describe('RewriteFrames', () => {
4446
],
4547
},
4648
};
49+
windowsExceptionEventWithoutPrefix = {
50+
exception: {
51+
values: [
52+
{
53+
stacktrace: {
54+
frames: [{ filename: 'www\\src\\app\\file1.js' }, { filename: 'www\\src\\app\\file2.js' }],
55+
},
56+
},
57+
],
58+
},
59+
};
60+
windowsExceptionEventWithBackslashPrefix = {
61+
exception: {
62+
values: [
63+
{
64+
stacktrace: {
65+
frames: [{ filename: '\\www\\src\\app\\file1.js' }, { filename: '\\www\\src\\app\\file2.js' }],
66+
},
67+
},
68+
],
69+
},
70+
};
4771
exceptionWithoutStackTrace = {
4872
exception: {
4973
values: [{}],
@@ -121,6 +145,18 @@ describe('RewriteFrames', () => {
121145
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///file1.js');
122146
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///file2.js');
123147
});
148+
149+
it('transforms windowsExceptionEvent frames with no prefix', () => {
150+
const event = rewriteFrames.process(windowsExceptionEventWithoutPrefix);
151+
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///file1.js');
152+
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///file2.js');
153+
});
154+
155+
it('transforms windowsExceptionEvent frames with backslash prefix', () => {
156+
const event = rewriteFrames.process(windowsExceptionEventWithBackslashPrefix);
157+
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///file1.js');
158+
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///file2.js');
159+
});
124160
});
125161

126162
describe('can use custom root to perform `relative` on filepaths', () => {
@@ -136,17 +172,29 @@ describe('RewriteFrames', () => {
136172
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///src/app/mo\\dule/file2.js');
137173
});
138174

139-
it('trasforms windowsExceptionEvent frames', () => {
175+
it('transforms windowsExceptionEvent frames', () => {
140176
const event = rewriteFrames.process(windowsExceptionEvent);
141177
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///src/app/file1.js');
142178
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///src/app/file2.js');
143179
});
144180

145-
it('trasforms windowsExceptionEvent lower-case prefix frames', () => {
181+
it('transforms windowsExceptionEvent lower-case prefix frames', () => {
146182
const event = rewriteFrames.process(windowsLowerCaseExceptionEvent);
147183
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///src/app/file1.js');
148184
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///src/app/file2.js');
149185
});
186+
187+
it('transforms windowsExceptionEvent frames with no prefix', () => {
188+
const event = rewriteFrames.process(windowsExceptionEventWithoutPrefix);
189+
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///src/app/file1.js');
190+
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///src/app/file2.js');
191+
});
192+
193+
it('transforms windowsExceptionEvent frames with backslash prefix', () => {
194+
const event = rewriteFrames.process(windowsExceptionEventWithBackslashPrefix);
195+
expect(event.exception!.values![0].stacktrace!.frames![0].filename).toEqual('app:///src/app/file1.js');
196+
expect(event.exception!.values![0].stacktrace!.frames![1].filename).toEqual('app:///src/app/file2.js');
197+
});
150198
});
151199

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

0 commit comments

Comments
 (0)