Skip to content

Commit

Permalink
Add: escapeIPv6
Browse files Browse the repository at this point in the history
  • Loading branch information
eight04 committed Oct 25, 2021
1 parent 2e0b49a commit d0c20e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/extension-runners/chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export class ChromiumExtensionRunner {
}
const ws = new window.WebSocket(
"ws://${wssInfo.address}:${wssInfo.port}");
"ws://${escapeIPv6(wssInfo.address)}:${wssInfo.port}");
ws.onmessage = async (evt) => {
const msg = JSON.parse(evt.data);
Expand Down Expand Up @@ -424,3 +424,10 @@ export class ChromiumExtensionRunner {
}
}
}

export function escapeIPv6(address: string): string {
if (/^([a-f0-9:]+:+)+[a-f0-9]+$/.test(address)) {
return `[${address}]`;
}
return address;
}
5 changes: 3 additions & 2 deletions tests/unit/test-extension-runners/test.chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import {
ChromiumExtensionRunner,
DEFAULT_CHROME_FLAGS,
escapeIPv6,
} from '../../../src/extension-runners/chromium';
import type {
ChromiumExtensionRunnerParams,
Expand Down Expand Up @@ -126,7 +127,7 @@ describe('util/extension-runners/chromium', async () => {

// $FlowIgnore: allow to call addess even wss property can be undefined.
const wssInfo = runnerInstance.wss.address();
const wsURL = `ws://${wssInfo.address}:${wssInfo.port}`;
const wsURL = `ws://${escapeIPv6(wssInfo.address)}:${wssInfo.port}`;
const wsClient = new WebSocket(wsURL);

await new Promise((resolve) => wsClient.on('open', resolve));
Expand Down Expand Up @@ -637,7 +638,7 @@ describe('util/extension-runners/chromium', async () => {
}
// $FlowIgnore: if runnerInstance.wss would be unexpectedly undefined the test case will fail.
const wssInfo = runnerInstance.wss.address();
const wsURL = `ws://${wssInfo.address}:${wssInfo.port}`;
const wsURL = `ws://${escapeIPv6(wssInfo.address)}:${wssInfo.port}`;
wsClient = new WebSocket(wsURL);
await new Promise((resolve) => wsClient.on('open', resolve));
};
Expand Down

0 comments on commit d0c20e7

Please sign in to comment.