From 461ab0cba7edf2ff1e6ca598fc5c7f9a8e9e4647 Mon Sep 17 00:00:00 2001 From: "mendral-app[bot]" <233154221+mendral-app[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2026 16:11:34 -0700 Subject: [PATCH] fix: validate empty resource name in parseForkArg Add a check for empty string when no type prefix is given, preventing invalid API calls with an empty target_name. Previously, an empty argument would pass through to the API which returned a 400 error. --- cli/fork.go | 3 +++ cli/fork_test.go | 1 + 2 files changed, 4 insertions(+) diff --git a/cli/fork.go b/cli/fork.go index 0711c76a..802b2b8c 100644 --- a/cli/fork.go +++ b/cli/fork.go @@ -42,6 +42,9 @@ func buildForkRequest(targetName, targetType string, traffic, port, memory *int) func parseForkArg(arg string) (resourceType, name string, err error) { parts := strings.SplitN(arg, "/", 2) if len(parts) == 1 { + if parts[0] == "" { + return "", "", fmt.Errorf("resource name must not be empty") + } return "", parts[0], nil } name = parts[1] diff --git a/cli/fork_test.go b/cli/fork_test.go index c18cb0e0..cbd652e1 100644 --- a/cli/fork_test.go +++ b/cli/fork_test.go @@ -19,6 +19,7 @@ func TestParseForkArg(t *testing.T) { {name: "untyped", arg: "source", resourceName: "source"}, {name: "sandbox", arg: "sbx/source", resourceType: "sandbox", resourceName: "source"}, {name: "application", arg: "application/target", resourceType: "application", resourceName: "target"}, + {name: "empty name", arg: "", wantErr: "resource name must not be empty"}, {name: "missing name", arg: "sbx/", wantErr: "missing name"}, {name: "unknown type", arg: "agent/source", wantErr: "unknown resource type"}, {name: "nested path", arg: "sbx/foo/bar", wantErr: "must not contain '/'"},