Simple browser opener doesn't work with IPv6 hosts (#159276)

Fixes #158599
This commit is contained in:
Alex Ross 2022-08-29 10:58:17 +02:00 committed by GitHub
parent 43ae27a30e
commit 41a6299276
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,6 +32,9 @@ const enabledHosts = new Set<string>([
'::'
]);
const IPv6Localhost = /0\:0\:0\:0\:0\:0\:0\:1|\:\:1/;
const IPv6AllInterfaces = /0\:0\:0\:0\:0\:0\:0\:0|\:\:/;
const openerId = 'simpleBrowser.open';
export function activate(context: vscode.ExtensionContext) {
@ -67,7 +70,8 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.window.registerExternalUriOpener(openerId, {
canOpenExternalUri(uri: vscode.Uri) {
const originalUri = new URL(uri.toString());
// We have to replace the IPv6 hosts with IPv4 because URL can't handle IPv6.
const originalUri = new URL(uri.toString().replace(IPv6Localhost, '127.0.0.1').replace(IPv6AllInterfaces, '0.0.0.0'));
if (enabledHosts.has(originalUri.hostname)) {
return isWeb()
? vscode.ExternalUriOpenerPriority.Default