Repository navigation
mcp: accept Windows drive letter file roots #1443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,23 +12,37 @@ import ( | |
| ) | ||
|
|
||
| func TestFileRoot(t *testing.T) { | ||
| if runtime.GOOS == "windows" { | ||
| t.Skip("TODO: fix for Windows") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are 3 other
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 16a042b. All three skips in |
||
| } | ||
|
|
||
| for _, tt := range []struct { | ||
| type test struct { | ||
| uri string | ||
| want string | ||
| wantErr string // error must contain this string | ||
| }{ | ||
| {uri: "file:///foo", want: "/foo"}, | ||
| {uri: "file:///foo/bar", want: "/foo/bar"}, | ||
| {uri: "file:///foo/../bar", want: "/bar"}, | ||
| {uri: "file:/foo", want: "/foo"}, | ||
| } | ||
| tests := []test{ | ||
| {uri: "http:///foo", wantErr: "not a file"}, | ||
| {uri: "file://foo", wantErr: "empty path"}, | ||
| {uri: ":", wantErr: "missing protocol scheme"}, | ||
| } { | ||
| } | ||
| if runtime.GOOS == "windows" { | ||
| tests = append(tests, | ||
| test{uri: "file:///C:/foo", want: `C:\foo`}, | ||
| test{uri: "file:///c:/foo/bar", want: `c:\foo\bar`}, | ||
| test{uri: "file:///C:/foo/../bar", want: `C:\bar`}, | ||
| test{uri: "file:/C:/foo", want: `C:\foo`}, | ||
| // VS Code percent-encodes the colon after the drive letter. | ||
| test{uri: "file:///c%3A/foo", want: `c:\foo`}, | ||
| test{uri: "file:///foo", wantErr: "not an absolute path"}, | ||
| test{uri: "file://localhost/C:/foo", want: `C:\foo`}, | ||
| test{uri: "file://server/share/foo", want: `\\server\share\foo`}, | ||
| ) | ||
| } else { | ||
| tests = append(tests, | ||
| test{uri: "file:///foo", want: "/foo"}, | ||
| test{uri: "file:///foo/bar", want: "/foo/bar"}, | ||
| test{uri: "file:///foo/../bar", want: "/bar"}, | ||
| test{uri: "file:/foo", want: "/foo"}, | ||
| ) | ||
| } | ||
| for _, tt := range tests { | ||
| got, err := fileRoot(&Root{URI: tt.uri}) | ||
| if err != nil { | ||
| if tt.wantErr == "" { | ||
|
|
@@ -47,10 +61,28 @@ func TestFileRoot(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestComputeURIFilepath(t *testing.T) { | ||
| if runtime.GOOS == "windows" { | ||
| t.Skip("TODO: fix for Windows") | ||
| func TestFileURIPath(t *testing.T) { | ||
| for _, tt := range []struct { | ||
| host, uriPath, goos, want string | ||
| }{ | ||
| {"", "/C:/foo", "windows", "C:/foo"}, | ||
| {"", "/c:/foo", "windows", "c:/foo"}, | ||
| {"", "/C:", "windows", "C:"}, | ||
| {"", "/foo", "windows", "/foo"}, | ||
| {"", "/1:/foo", "windows", "/1:/foo"}, | ||
| {"localhost", "/C:/foo", "windows", "C:/foo"}, | ||
| {"server", "/share/foo", "windows", "//server/share/foo"}, | ||
| {"", "/C:/foo", "linux", "/C:/foo"}, | ||
| {"", "/foo", "linux", "/foo"}, | ||
| {"server", "/share/foo", "linux", "/share/foo"}, | ||
| } { | ||
| if got := fileURIPath(tt.host, tt.uriPath, tt.goos); got != tt.want { | ||
| t.Errorf("fileURIPath(%q, %q, %q) = %q, want %q", tt.host, tt.uriPath, tt.goos, got, tt.want) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestComputeURIFilepath(t *testing.T) { | ||
| // TODO(jba): test with Windows \\host paths and C: paths | ||
| dirFilepath := filepath.FromSlash("/files") | ||
| rootFilepaths := []string{ | ||
|
|
@@ -95,9 +127,6 @@ func TestComputeURIFilepath(t *testing.T) { | |
| } | ||
|
|
||
| func TestReadFileResource(t *testing.T) { | ||
| if runtime.GOOS == "windows" { | ||
| t.Skip("TODO: fix for Windows") | ||
| } | ||
| abs, err := filepath.Abs("testdata") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
|
|
@@ -136,9 +165,6 @@ func TestTemplateMatch(t *testing.T) { | |
| // error. Regression: the message formatted filepath.Localize's error-path | ||
| // return value, which is always "", so it never identified the offending path. | ||
| func TestComputeURIFilepathLocalizeError(t *testing.T) { | ||
| if runtime.GOOS == "windows" { | ||
| t.Skip("TODO: fix for Windows") | ||
| } | ||
| dirFilepath := filepath.FromSlash("/files") | ||
| _, err := computeURIFilepath("file://foo/../bar", dirFilepath, nil) | ||
| if err == nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's handle UNC path as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 16a042b. On Windows, a host other than
localhostis now a UNC path (RFC 8089, Appendix E.3.1):file://server/share/foogives\server\share\foo, andfile://localhost/C:/foostill givesC:\foo. On other systems the host is ignored as before.fileURIPathtakes the host now, andTestFileURIPathandTestFileRoothave cases for both.