Skip to content

Commit 6871998

Browse files
Copilotsawka
andauthored
Fix connparse handling for scheme-less //... WSH shorthand URIs (#3006)
`pkg/remote/connparse` was failing on shorthand WSH inputs that omit the `wsh://` scheme, including remote hosts, WSL targets, and Windows local paths. The parser was splitting on `://` too early and misclassifying leading `//` inputs before WSH shorthand handling ran. - **What changed** - Detect scheme-less WSH shorthand up front with `strings.HasPrefix(uri, "//")` - Route those inputs through the existing WSH path parsing flow instead of the generic `://` split path - Reuse the same shorthand flag when deciding whether to parse as remote/local WSH vs current-path shorthand - **Behavioral impact** - `//conn/path/to/file` now parses as host `conn` with path `path/to/file` - `//wsl://Ubuntu/path/to/file` now preserves the WSL host and absolute path shape - `//local/C:\path\to\file` now parses as local Windows shorthand instead of being treated as a current-path string - **Scope** - Keeps the existing test expectations intact - Limits the change to `pkg/remote/connparse/connparse.go` ```go isWshShorthand := strings.HasPrefix(uri, "//") if isWshShorthand { rest = strings.TrimPrefix(uri, "//") } else if len(split) > 1 { scheme = split[0] rest = strings.TrimPrefix(split[1], "//") } ``` <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sawka <2722291+sawka@users.noreply.github.com> Co-authored-by: sawka <mike@commandline.dev>
1 parent 46593b9 commit 6871998

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

pkg/remote/connparse/connparse.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,13 @@ func GetConnNameFromContext(ctx context.Context) (string, error) {
9292

9393
// ParseURI parses a connection URI and returns the connection type, host/path, and parameters.
9494
func ParseURI(uri string) (*Connection, error) {
95+
isWshShorthand := strings.HasPrefix(uri, "//")
9596
split := strings.SplitN(uri, "://", 2)
9697
var scheme string
9798
var rest string
98-
if len(split) > 1 {
99+
if isWshShorthand {
100+
rest = strings.TrimPrefix(uri, "//")
101+
} else if len(split) > 1 {
99102
scheme = split[0]
100103
rest = strings.TrimPrefix(split[1], "//")
101104
} else {
@@ -131,8 +134,7 @@ func ParseURI(uri string) (*Connection, error) {
131134
if scheme == "" {
132135
scheme = ConnectionTypeWsh
133136
addPrecedingSlash = false
134-
if len(rest) != len(uri) {
135-
// This accounts for when the uri starts with "//", which would get trimmed in the first split.
137+
if isWshShorthand {
136138
parseWshPath()
137139
} else if strings.HasPrefix(rest, "/~") {
138140
host = wshrpc.LocalConnName

pkg/remote/connparse/connparse_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ func TestParseURI_WSHRemoteShorthand(t *testing.T) {
8181
if c.Path != expected {
8282
t.Fatalf("expected path to be \"%q\", got \"%q\"", expected, c.Path)
8383
}
84-
if c.Host != "conn" {
85-
t.Fatalf("expected host to be empty, got \"%q\"", c.Host)
84+
expected = "conn"
85+
if c.Host != expected {
86+
t.Fatalf("expected host to be \"%q\", got \"%q\"", expected, c.Host)
8687
}
8788
expected = "wsh"
8889
if c.Scheme != expected {

0 commit comments

Comments
 (0)