Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Aug 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion extensions/simple-browser/src/extension.ts
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down