Skip to content

Commit 496724f

Browse files
EdmondChuiHWfacebook-github-bot
authored andcommitted
Remove URI encoding
Summary: Changelog: [Internal] Fixed double-encoding for the websocket url. `URLSearchParams` already encode the values, passing a pre-encoded `encodeUriComponent` string will cause it to double-encode, making the value unreadable when decoding once. Missed these lines while splitting the initial diff stack. Added tests now. Reviewed By: motiz88 Differential Revision: D53721568 fbshipit-source-id: cfaaa7eb50c40364c904e9ffc5698201df8ab22b
1 parent 3272b05 commit 496724f

File tree

2 files changed

+104
-2
lines changed

2 files changed

+104
-2
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
* @oncall react_native
10+
*/
11+
12+
import getDevToolsFrontendUrl from '../utils/getDevToolsFrontendUrl';
13+
14+
describe('getDevToolsFrontendUrl', () => {
15+
const webSocketDebuggerUrl =
16+
'ws://localhost:8081/inspector/debug?device=1a9372c&page=-1';
17+
18+
describe('given an absolute devServerUrl', () => {
19+
const devServerUrl = 'http://localhost:8081';
20+
21+
it('should return a valid url for all experiments off', async () => {
22+
const experiments = {
23+
enableNetworkInspector: false,
24+
enableNewDebugger: false,
25+
enableOpenDebuggerRedirect: false,
26+
};
27+
const actual = getDevToolsFrontendUrl(
28+
experiments,
29+
webSocketDebuggerUrl,
30+
devServerUrl,
31+
);
32+
const decoded = decodeURIComponent(actual);
33+
const doubleDecoded = decodeURIComponent(decoded);
34+
expect(decoded).toBe(doubleDecoded);
35+
expect(actual).toMatchInlineSnapshot(
36+
`"http://localhost:8081/debugger-frontend/rn_inspector.html?ws=localhost%3A8081%2Finspector%2Fdebug%3Fdevice%3D1a9372c%26page%3D-1&sources.hide_add_folder=true"`,
37+
);
38+
});
39+
40+
it('should return a valid url for enableNetworkInspector experiment on', async () => {
41+
const experiments = {
42+
enableNetworkInspector: true,
43+
enableNewDebugger: true,
44+
enableOpenDebuggerRedirect: false,
45+
};
46+
const actual = getDevToolsFrontendUrl(
47+
experiments,
48+
webSocketDebuggerUrl,
49+
devServerUrl,
50+
);
51+
const decoded = decodeURIComponent(actual);
52+
const doubleDecoded = decodeURIComponent(decoded);
53+
expect(decoded).toBe(doubleDecoded);
54+
expect(actual).toMatchInlineSnapshot(
55+
`"http://localhost:8081/debugger-frontend/rn_inspector.html?ws=localhost%3A8081%2Finspector%2Fdebug%3Fdevice%3D1a9372c%26page%3D-1&sources.hide_add_folder=true&unstable_enableNetworkPanel=true"`,
56+
);
57+
});
58+
});
59+
60+
describe('given a relative devServerUrl', () => {
61+
const devServerUrl = '';
62+
63+
it('should return a valid url for all experiments off', async () => {
64+
const experiments = {
65+
enableNetworkInspector: false,
66+
enableNewDebugger: false,
67+
enableOpenDebuggerRedirect: false,
68+
};
69+
const actual = getDevToolsFrontendUrl(
70+
experiments,
71+
webSocketDebuggerUrl,
72+
devServerUrl,
73+
);
74+
const decoded = decodeURIComponent(actual);
75+
const doubleDecoded = decodeURIComponent(decoded);
76+
expect(decoded).toBe(doubleDecoded);
77+
expect(actual).toMatchInlineSnapshot(
78+
`"/debugger-frontend/rn_inspector.html?ws=localhost%3A8081%2Finspector%2Fdebug%3Fdevice%3D1a9372c%26page%3D-1&sources.hide_add_folder=true"`,
79+
);
80+
});
81+
82+
it('should return a valid url for enableNetworkInspector experiment on', async () => {
83+
const experiments = {
84+
enableNetworkInspector: true,
85+
enableNewDebugger: true,
86+
enableOpenDebuggerRedirect: false,
87+
};
88+
const actual = getDevToolsFrontendUrl(
89+
experiments,
90+
webSocketDebuggerUrl,
91+
devServerUrl,
92+
);
93+
const decoded = decodeURIComponent(actual);
94+
const doubleDecoded = decodeURIComponent(decoded);
95+
expect(decoded).toBe(doubleDecoded);
96+
expect(actual).toMatchInlineSnapshot(
97+
`"/debugger-frontend/rn_inspector.html?ws=localhost%3A8081%2Finspector%2Fdebug%3Fdevice%3D1a9372c%26page%3D-1&sources.hide_add_folder=true&unstable_enableNetworkPanel=true"`,
98+
);
99+
});
100+
});
101+
});

packages/dev-middleware/src/utils/getDevToolsFrontendUrl.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ export default function getDevToolsFrontendUrl(
2020
devServerUrl: string,
2121
): string {
2222
const scheme = new URL(webSocketDebuggerUrl).protocol.slice(0, -1);
23-
const webSocketUrlWithoutProtocol = encodeURIComponent(
24-
webSocketDebuggerUrl.replace(/^wss?:\/\//, ''),
23+
const webSocketUrlWithoutProtocol = webSocketDebuggerUrl.replace(
24+
/^wss?:\/\//,
25+
'',
2526
);
2627
const appUrl = `${devServerUrl}/debugger-frontend/rn_inspector.html`;
2728

0 commit comments

Comments
 (0)