forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
3272b05
commit 496724f
Showing
2 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
packages/dev-middleware/src/__tests__/getDevToolsFrontendUrl-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
import getDevToolsFrontendUrl from '../utils/getDevToolsFrontendUrl'; | ||
|
||
describe('getDevToolsFrontendUrl', () => { | ||
const webSocketDebuggerUrl = | ||
'ws://localhost:8081/inspector/debug?device=1a9372c&page=-1'; | ||
|
||
describe('given an absolute devServerUrl', () => { | ||
const devServerUrl = 'http://localhost:8081'; | ||
|
||
it('should return a valid url for all experiments off', async () => { | ||
const experiments = { | ||
enableNetworkInspector: false, | ||
enableNewDebugger: false, | ||
enableOpenDebuggerRedirect: false, | ||
}; | ||
const actual = getDevToolsFrontendUrl( | ||
experiments, | ||
webSocketDebuggerUrl, | ||
devServerUrl, | ||
); | ||
const decoded = decodeURIComponent(actual); | ||
const doubleDecoded = decodeURIComponent(decoded); | ||
expect(decoded).toBe(doubleDecoded); | ||
expect(actual).toMatchInlineSnapshot( | ||
`"http://localhost:8081/debugger-frontend/rn_inspector.html?ws=localhost%3A8081%2Finspector%2Fdebug%3Fdevice%3D1a9372c%26page%3D-1&sources.hide_add_folder=true"`, | ||
); | ||
}); | ||
|
||
it('should return a valid url for enableNetworkInspector experiment on', async () => { | ||
const experiments = { | ||
enableNetworkInspector: true, | ||
enableNewDebugger: true, | ||
enableOpenDebuggerRedirect: false, | ||
}; | ||
const actual = getDevToolsFrontendUrl( | ||
experiments, | ||
webSocketDebuggerUrl, | ||
devServerUrl, | ||
); | ||
const decoded = decodeURIComponent(actual); | ||
const doubleDecoded = decodeURIComponent(decoded); | ||
expect(decoded).toBe(doubleDecoded); | ||
expect(actual).toMatchInlineSnapshot( | ||
`"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"`, | ||
); | ||
}); | ||
}); | ||
|
||
describe('given a relative devServerUrl', () => { | ||
const devServerUrl = ''; | ||
|
||
it('should return a valid url for all experiments off', async () => { | ||
const experiments = { | ||
enableNetworkInspector: false, | ||
enableNewDebugger: false, | ||
enableOpenDebuggerRedirect: false, | ||
}; | ||
const actual = getDevToolsFrontendUrl( | ||
experiments, | ||
webSocketDebuggerUrl, | ||
devServerUrl, | ||
); | ||
const decoded = decodeURIComponent(actual); | ||
const doubleDecoded = decodeURIComponent(decoded); | ||
expect(decoded).toBe(doubleDecoded); | ||
expect(actual).toMatchInlineSnapshot( | ||
`"/debugger-frontend/rn_inspector.html?ws=localhost%3A8081%2Finspector%2Fdebug%3Fdevice%3D1a9372c%26page%3D-1&sources.hide_add_folder=true"`, | ||
); | ||
}); | ||
|
||
it('should return a valid url for enableNetworkInspector experiment on', async () => { | ||
const experiments = { | ||
enableNetworkInspector: true, | ||
enableNewDebugger: true, | ||
enableOpenDebuggerRedirect: false, | ||
}; | ||
const actual = getDevToolsFrontendUrl( | ||
experiments, | ||
webSocketDebuggerUrl, | ||
devServerUrl, | ||
); | ||
const decoded = decodeURIComponent(actual); | ||
const doubleDecoded = decodeURIComponent(decoded); | ||
expect(decoded).toBe(doubleDecoded); | ||
expect(actual).toMatchInlineSnapshot( | ||
`"/debugger-frontend/rn_inspector.html?ws=localhost%3A8081%2Finspector%2Fdebug%3Fdevice%3D1a9372c%26page%3D-1&sources.hide_add_folder=true&unstable_enableNetworkPanel=true"`, | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters