1
>
/*---------------------------------------------------------------------------------------------
domainMatcher.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { URI } from '../../../base/common/uri.js';
7
>
8
>
/**
9
>
* Common file extensions that are unlikely to be network domains.
10
>
* Used to filter false positives when extracting domains from freeform text.
11
>
*/
12
>
const fileExtensionSuffixes = new Set([
13
>
'7z', 'bz2', 'cjs', 'class', 'cpp', 'cs', 'css', 'csv', 'dll', 'exe', 'gif', 'gz', 'ico', 'jar',
14
>
'env', 'java', 'jpeg', 'jpg', 'js', 'json', 'jsx', 'lock', 'log', 'md', 'mjs', 'pdf', 'php', 'png',
15
>
'py', 'rar', 'rs', 'so', 'sql', 'svg', 'tar', 'tgz', 'toml', 'ts', 'tsx', 'txt', 'wasm', 'webp',
16
>
'xml', 'yaml', 'yml', 'zip'
17
>
]);
18
>
19
>
/**
20
>
* Bare host detection is a heuristic used only to prompt before running commands that appear to access the network.
21
>
* Keep this list intentionally conservative and focused on TLDs commonly used for coding-related hosts and services.
22
>
*/
23
>
const wellKnownDomainSuffixes = new Set([
24
>
'ai', 'cloud', 'com', 'dev', 'io', 'me', 'net', 'org', 'tech'
25
>
]);
26
>
27
>
/**
28
>
* Normalizes and validates a domain string.
29
>
*
30
>
* Strips user info, port, trailing dots, and trailing punctuation.
31
>
* Accepts bare wildcards (`*`) and wildcard prefixes (`*.example.com`).
32
>
*
33
>
* @param value The raw domain string to normalize.
34
>
* @param fromUrl Whether the value was extracted from a URL context (skips file-extension filtering).
35
>
* @returns The normalized domain string, or `undefined` if the input is invalid.
36
>
*/
37
>
export function normalizeDomain(value: string | undefined, fromUrl: boolean = false): string | undefined {
38
if (!value) {
39
return undefined;