From 18b80c5d2fd66cf4c9b44e81da4e449fd4142438 Mon Sep 17 00:00:00 2001 From: Kelvin Schoofs Date: Wed, 7 Apr 2021 20:26:07 +0200 Subject: [PATCH] Allow connection strings to start with `ssh://`, `scp://` and `sftp://` --- src/fileSystemConfig.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/fileSystemConfig.ts b/src/fileSystemConfig.ts index 2d6b35a..b7bba31 100644 --- a/src/fileSystemConfig.ts +++ b/src/fileSystemConfig.ts @@ -135,9 +135,14 @@ export function invalidConfigName(name: string) { */ const CONNECTION_REGEX = /^((?\w+)?(;[\w-]+=[\w\d-]+(,[\w\d-]+=[\w\d-]+)*)?@)?(?[^@\\/:,=]+)(:(?\d+))?(?\/.*)?$/; +const PREFIX_REGEX = /^(ssh|scp|sftp):\/\/(?.*)$/; + +/** Based on CONNECTION_REGEX, but also strips leading `ssh://`, `scp://` or `sftp://` if present. */ export function parseConnectionString(input: string): [config: FileSystemConfig, path?: string] | string { input = input.trim(); - const match = input.match(CONNECTION_REGEX); + let match = input.match(PREFIX_REGEX); + if (match) input = match.groups!.input; + match = input.match(CONNECTION_REGEX); if (!match) return 'Invalid format, expected something like "user@example.com:22/some/path"'; const { user, host, path } = match.groups!; const portStr = match.groups!.port;