diff --git a/internal/config/config.go b/internal/config/config.go index 5f7fd1a..87a6ce3 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -122,12 +122,13 @@ func getPort() (int, error) { return defaultPort, nil } - port, err := strconv.Atoi(value) + // ParseUint, unlike Atoi, refuses a sign: the health check URL cannot use "+9090" + port, err := strconv.ParseUint(value, 10, 0) if err != nil || port < 1 || port > maxPort { return 0, fmt.Errorf("PORT must be a whole number from 1 to %d, got %q", maxPort, value) } - return port, nil + return int(port), nil } // EnsureDirectories creates all necessary directories if they don't exist diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 1b3bca7..84f9414 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -31,7 +31,7 @@ func TestNewReadsPort(t *testing.T) { } func TestNewRefusesInvalidPort(t *testing.T) { - for _, value := range []string{"0", "65536", "-1", "http", "80.5"} { + for _, value := range []string{"0", "65536", "-1", "+9090", "http", "80.5"} { t.Run(value, func(t *testing.T) { t.Setenv("PORT", value) t.Setenv("XDG_DATA_HOME", "")