Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions apps/server/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func ParseRunConfig(argv []string, env map[string]string, cwd string) (RuntimeCo
args = args[1:]
}

host := getOrDefault(env["WOOTTY_HOST"], DefaultHost)
host := normalizeHost(env["WOOTTY_HOST"], DefaultHost)
port := parsePositiveInt(env["WOOTTY_PORT"], DefaultPort)
if strings.TrimSpace(env["WOOTTY_RECONNECT_GRACE_MS"]) != "" {
return RuntimeConfig{}, errors.New(
Expand Down Expand Up @@ -70,7 +70,7 @@ func ParseRunConfig(argv []string, env map[string]string, cwd string) (RuntimeCo
case "--host":
i++
if i < len(args) && strings.TrimSpace(args[i]) != "" {
host = args[i]
host = strings.TrimSpace(args[i])
}
continue
case "--detached-ttl-ms":
Expand Down Expand Up @@ -344,6 +344,14 @@ func getOrDefault(value string, fallback string) string {
return value
}

func normalizeHost(value string, fallback string) string {
trimmed := strings.TrimSpace(value)
if trimmed == "" {
return fallback
}
return trimmed
}

func parseCSVList(value string) []string {
trimmed := strings.TrimSpace(value)
if trimmed == "" {
Expand Down
28 changes: 28 additions & 0 deletions apps/server/internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,34 @@ func TestParseRunConfigParsesAllowedOrigins(t *testing.T) {
}
}

func TestParseRunConfigTrimsHostFromEnvironment(t *testing.T) {
cfg, err := ParseRunConfig(
[]string{"run"},
map[string]string{"WOOTTY_HOST": " 127.0.0.1 "},
"/tmp/wootty/apps/server",
)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if cfg.Host != "127.0.0.1" {
t.Fatalf("expected trimmed host from env, got %q", cfg.Host)
}
}

func TestParseRunConfigTrimsHostFromFlag(t *testing.T) {
cfg, err := ParseRunConfig(
[]string{"run", "--host", " 127.0.0.1 "},
map[string]string{},
"/tmp/wootty/apps/server",
)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if cfg.Host != "127.0.0.1" {
t.Fatalf("expected trimmed host from flag, got %q", cfg.Host)
}
}

func TestParseRunConfigUnknownFlag(t *testing.T) {
_, err := ParseRunConfig([]string{"run", "--nope"}, map[string]string{}, "/tmp/wootty/apps/server")
if err == nil {
Expand Down
Loading