diff --git a/pkg/remote/connparse/connparse.go b/pkg/remote/connparse/connparse.go index 349003aafd..a4b8e99c3d 100644 --- a/pkg/remote/connparse/connparse.go +++ b/pkg/remote/connparse/connparse.go @@ -92,10 +92,13 @@ func GetConnNameFromContext(ctx context.Context) (string, error) { // ParseURI parses a connection URI and returns the connection type, host/path, and parameters. func ParseURI(uri string) (*Connection, error) { + isWshShorthand := strings.HasPrefix(uri, "//") split := strings.SplitN(uri, "://", 2) var scheme string var rest string - if len(split) > 1 { + if isWshShorthand { + rest = strings.TrimPrefix(uri, "//") + } else if len(split) > 1 { scheme = split[0] rest = strings.TrimPrefix(split[1], "//") } else { @@ -131,8 +134,7 @@ func ParseURI(uri string) (*Connection, error) { if scheme == "" { scheme = ConnectionTypeWsh addPrecedingSlash = false - if len(rest) != len(uri) { - // This accounts for when the uri starts with "//", which would get trimmed in the first split. + if isWshShorthand { parseWshPath() } else if strings.HasPrefix(rest, "/~") { host = wshrpc.LocalConnName diff --git a/pkg/remote/connparse/connparse_test.go b/pkg/remote/connparse/connparse_test.go index e883ef3fb6..82a36387b7 100644 --- a/pkg/remote/connparse/connparse_test.go +++ b/pkg/remote/connparse/connparse_test.go @@ -81,8 +81,9 @@ func TestParseURI_WSHRemoteShorthand(t *testing.T) { if c.Path != expected { t.Fatalf("expected path to be \"%q\", got \"%q\"", expected, c.Path) } - if c.Host != "conn" { - t.Fatalf("expected host to be empty, got \"%q\"", c.Host) + expected = "conn" + if c.Host != expected { + t.Fatalf("expected host to be \"%q\", got \"%q\"", expected, c.Host) } expected = "wsh" if c.Scheme != expected {