@samitouri / QOS-React-2 / commits / 1631855f43

[Flight] encodeURI filenames parsed from stack traces (#31340)

When parsing stacks from third parties they may include invalid url characters. So we need to encode them. Since these are expected to be urls though we use just encodeURI instead of encodeURIComponent.

Sebastian Markbåge committed Oct 23, 2024 at 16:29 UTC 1631855f4303cc8585205307a56c69e3b7248bb4
2 files changed +4 -4
packages/react-client/src/ReactFlightClient.js
+2 -2
@@ -2275,12 +2275,12 @@ function createFakeFunction<T>(
2275 '\n//# sourceURL=rsc://React/' +
2276 encodeURIComponent(environmentName) +
2277 '/' +
2278 - filename +
2278 + encodeURI(filename) +
2279 '?' +
2280 fakeFunctionIdx++;
2281 code += '\n//# sourceMappingURL=' + sourceMap;
2282 } else if (filename) {
2283 - code += '\n//# sourceURL=' + filename;
2283 + code += '\n//# sourceURL=' + encodeURI(filename);
2284 } else {
2285 code += '\n//# sourceURL=<anonymous>';
2286 }
packages/react-client/src/__tests__/ReactFlight-test.js
+2 -2
@@ -1363,7 +1363,7 @@ describe('ReactFlight', () => {
1363 )
1364 ? expect.stringContaining(
1365 'Error: This is an error\n' +
1366 - ' at eval (eval at testFunction (eval at createFakeFunction (**), <anonymous>:1:35)\n' +
1366 + ' at eval (eval at testFunction (inspected-page.html:29:11),%20%3Canonymous%3E:1:35)\n' +
1367 ' at ServerComponentError (file://~/(some)(really)(exotic-directory)/ReactFlight-test.js:1166:19)\n' +
1368 ' at <anonymous> (file:///testing.js:42:3)\n' +
1369 ' at <anonymous> (file:///testing.js:42:3)\n' +
@@ -1371,7 +1371,7 @@ describe('ReactFlight', () => {
1371 )
1372 : expect.stringContaining(
1373 'Error: This is an error\n' +
1374 - ' at eval (eval at testFunction (inspected-page.html:29:11), <anonymous>:1:10)\n' +
1374 + ' at eval (eval at testFunction (inspected-page.html:29:11),%20%3Canonymous%3E:1:10)\n' +
1375 ' at ServerComponentError (file://~/(some)(really)(exotic-directory)/ReactFlight-test.js:1166:19)\n' +
1376 ' at file:///testing.js:42:3\n' +
1377 ' at file:///testing.js:42:3\n' +