Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit285ae7f

Browse files
committed
review
1 parent4f45cee commit285ae7f

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

‎agent/ls.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66
"os"
77
"path/filepath"
8+
"regexp"
89
"runtime"
910
"strings"
1011

@@ -59,6 +60,10 @@ func listFiles(query LSRequest) (LSResponse, error) {
5960
iflen(query.Path)==0 {
6061
returnlistDrives()
6162
}
63+
re:=regexp.MustCompile(`^[a-zA-Z]:\\$`)
64+
if!re.MatchString(query.Path[0]) {
65+
returnLSResponse{},xerrors.Errorf("invalid drive letter %q",query.Path[0])
66+
}
6267
}else {
6368
fullPath= []string{"/"}
6469
}

‎agent/ls_internal_test.go

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ func TestListFilesSuccess(t *testing.T) {
115115
err=os.Mkdir(downloadsDir,0o755)
116116
require.NoError(t,err)
117117

118+
textFile:=filepath.Join(tmpDir,"file.txt")
119+
err=os.WriteFile(textFile, []byte("content"),0o600)
120+
require.NoError(t,err)
121+
118122
varqueryComponents []string
119123
// We can't get an absolute path relative to empty string on Windows.
120124
ifruntime.GOOS=="windows"&&base=="" {
@@ -133,23 +137,23 @@ func TestListFilesSuccess(t *testing.T) {
133137
require.NoError(t,err)
134138

135139
require.Equal(t,tmpDir,resp.AbsolutePathString)
136-
137-
varfoundRepos,foundDownloadsbool
138-
for_,file:=rangeresp.Contents {
139-
switchfile.Name {
140-
case"repos":
141-
foundRepos=true
142-
expectedPath:=filepath.Join(tmpDir,"repos")
143-
require.Equal(t,expectedPath,file.AbsolutePathString)
144-
require.True(t,file.IsDir)
145-
case"Downloads":
146-
foundDownloads=true
147-
expectedPath:=filepath.Join(tmpDir,"Downloads")
148-
require.Equal(t,expectedPath,file.AbsolutePathString)
149-
require.True(t,file.IsDir)
150-
}
151-
}
152-
require.True(t,foundRepos&&foundDownloads,"expected to find both repos and Downloads directories, got: %+v",resp.Contents)
140+
require.ElementsMatch(t, []LSFile{
141+
{
142+
Name:"repos",
143+
AbsolutePathString:reposDir,
144+
IsDir:true,
145+
},
146+
{
147+
Name:"Downloads",
148+
AbsolutePathString:downloadsDir,
149+
IsDir:true,
150+
},
151+
{
152+
Name:"file.txt",
153+
AbsolutePathString:textFile,
154+
IsDir:false,
155+
},
156+
},resp.Contents)
153157
})
154158
}
155159
}
@@ -186,4 +190,12 @@ func TestListFilesListDrives(t *testing.T) {
186190
}
187191
resp,err=listFiles(query)
188192
require.NoError(t,err)
193+
194+
query=LSRequest{
195+
// Network drives are not supported.
196+
Path: []string{"\\sshfs\\work"},
197+
Relativity:LSRelativityRoot,
198+
}
199+
resp,err=listFiles(query)
200+
require.ErrorContains(t,err,"drive")
189201
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp