Skip to content

fix: only autofill "debug link" input if the hostname resolves #2096

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

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ This changelog records changes to stable releases since 1.50.2. "TBA" changes he

## Nightly (only)

Nothing, yet
- fix: only autofill "debug link" input if the hostname resolves ([vscode#228950](https://github.com/microsoft/vscode/issues/228950))
- fix: support ANSI colorization in stdout logged strings ([vscode#230441](https://github.com/microsoft/vscode/issues/230441))
- fix: disable entrypoint breakpoint at first pause in script ([vscode#230201](https://github.com/microsoft/vscode/issues/230201))
- fix: avoid generating extra rebased paths in relative `rebaseLocalToRemote` ([#2091](https://github.com/microsoft/vscode-js-debug/issues/2091))

## v1.94 (September 2024)

Expand Down
20 changes: 16 additions & 4 deletions src/ui/debugLinkUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*--------------------------------------------------------*/

import * as l10n from '@vscode/l10n';
import * as dns from 'dns/promises';
import { inject, injectable } from 'inversify';
import { URL } from 'url';
import * as vscode from 'vscode';
Expand All @@ -14,16 +15,26 @@ import {
readConfig,
} from '../common/contributionUtils';
import { DefaultBrowser, IDefaultBrowserProvider } from '../common/defaultBrowserProvider';
import { delay } from '../common/promiseUtil';
import { ExtensionContext, IExtensionContribution } from '../ioc-extras';

function getPossibleUrl(link: string, requirePort: boolean): string | undefined {
async function assertResolves(hostname: string, timeout = 1000) {
return Promise.race([
dns.lookup(hostname),
delay(timeout),
]);
}

async function getPossibleUrl(link: string, requirePort: boolean): Promise<string | undefined> {
if (!link) {
return;
}

// if the link is already valid, all good
try {
if (new URL(link).hostname) {
const url = new URL(link);
if (url.hostname) {
await assertResolves(url.hostname); // ensure it can be resolved
return link;
}
} catch {
Expand All @@ -34,6 +45,7 @@ function getPossibleUrl(link: string, requirePort: boolean): string | undefined
try {
const prefixed = `http://${link}`;
const url = new URL(prefixed);
await assertResolves(url.hostname);
if (!requirePort || url.port) {
return prefixed;
}
Expand Down Expand Up @@ -103,10 +115,10 @@ export class DebugLinkUi implements IExtensionContribution {
private async getLinkFromQuickInput() {
const clipboard = await vscode.env.clipboard.readText();
const link = await vscode.window.showInputBox({
value: getPossibleUrl(clipboard, false) || this.mostRecentLink,
value: await getPossibleUrl(clipboard, false) || this.mostRecentLink,
placeHolder: 'https://localhost:8080',
validateInput: input => {
if (input && !getPossibleUrl(input, false)) {
if (input && !URL.canParse(input)) {
return l10n.t('The URL provided is invalid');
}
},
Expand Down
Loading