mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 11:38:51 +01:00
Fix parseAddress regex (#140977)
The previous regex was not very good and meant that hostnames containing digits and full stops were not accepted. This one should be more accurate. You can test it [here](https://regex101.com/r/ZVItcq/1). Because regex's are completely unreadable here's how it breaks down: ``` ^ - Start ( - Hostname group [a-zA-Z0-9-]+ - First domain component (?: - Optional subsequent components \.[a-zA-Z0-9-]+ - Each subsequent component is a . followed by the component )* - Any number of subsequent components : - Port separator )? - Hostname group is optional ([0-9]+) - Port, which is mandator $ - End ```
This commit is contained in:
@@ -120,7 +120,7 @@ export function makeAddress(host: string, port: number): string {
|
||||
}
|
||||
|
||||
export function parseAddress(address: string): { host: string, port: number } | undefined {
|
||||
const matches = address.match(/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\:|localhost:|[a-zA-Z\-]+:)?([0-9]+)$/);
|
||||
const matches = address.match(/^([a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*:)?([0-9]+)$/);
|
||||
if (!matches) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user