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

Commitc63c4a9

Browse files
committed
Move edit length check above file open
1 parent48a1956 commitc63c4a9

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

‎agent/files.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ func (a *agent) editFile(path string, edits []workspacesdk.FileEdit) (int, error
208208
returnhttp.StatusBadRequest,xerrors.Errorf("file path must be absolute: %q",path)
209209
}
210210

211+
iflen(edits)==0 {
212+
returnhttp.StatusBadRequest,xerrors.New("must specify at least one edit")
213+
}
214+
211215
f,err:=a.filesystem.Open(path)
212216
iferr!=nil {
213217
status:=http.StatusInternalServerError
@@ -230,10 +234,6 @@ func (a *agent) editFile(path string, edits []workspacesdk.FileEdit) (int, error
230234
returnhttp.StatusBadRequest,xerrors.Errorf("open %s: not a file",path)
231235
}
232236

233-
iflen(edits)==0 {
234-
returnhttp.StatusBadRequest,xerrors.New("must specify at least one edit")
235-
}
236-
237237
transforms:=make([]transform.Transformer,len(edits))
238238
fori,edit:=rangeedits {
239239
transforms[i]=replace.String(edit.Search,edit.Replace)

‎agent/files_test.go‎

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -435,30 +435,48 @@ func TestEditFile(t *testing.T) {
435435
error:"file path must be absolute",
436436
},
437437
{
438-
name:"NonExistent",
439-
path:filepath.Join(tmpdir,"does-not-exist"),
438+
name:"NoEdits",
439+
path:filepath.Join(tmpdir,"no-edits"),
440+
contents:"foo bar",
441+
errCode:http.StatusBadRequest,
442+
error:"must specify at least one edit",
443+
},
444+
{
445+
name:"NonExistent",
446+
path:filepath.Join(tmpdir,"does-not-exist"),
447+
edits: []workspacesdk.FileEdit{
448+
{
449+
Search:"foo",
450+
Replace:"bar",
451+
},
452+
},
440453
errCode:http.StatusNotFound,
441454
error:"file does not exist",
442455
},
443456
{
444-
name:"IsDir",
445-
path:dirPath,
457+
name:"IsDir",
458+
path:dirPath,
459+
edits: []workspacesdk.FileEdit{
460+
{
461+
Search:"foo",
462+
Replace:"bar",
463+
},
464+
},
446465
errCode:http.StatusBadRequest,
447466
error:"not a file",
448467
},
449468
{
450-
name:"NoPermissions",
451-
path:noPermsFilePath,
469+
name:"NoPermissions",
470+
path:noPermsFilePath,
471+
edits: []workspacesdk.FileEdit{
472+
{
473+
Search:"foo",
474+
Replace:"bar",
475+
},
476+
},
452477
errCode:http.StatusForbidden,
453478
error:"permission denied",
454479
},
455-
{
456-
name:"NoEdits",
457-
path:filepath.Join(tmpdir,"no-edits"),
458-
contents:"foo bar",
459-
errCode:http.StatusBadRequest,
460-
error:"must specify at least one edit",
461-
},
462480
{
463481
name:"FailRename",
464482
path:failRenameFilePath,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp