diff --git a/README.md b/README.md index c688000..48677d3 100644 --- a/README.md +++ b/README.md @@ -624,6 +624,8 @@ To compare two results files you already have, without scanning, use `subenum di No flags required. Fill in the form and press `ctrl+r` to start scanning. Last-used values are saved to `last.json` in your user config directory (`~/.config/subenum/` on Linux, `~/Library/Application Support/subenum/` on macOS, `%AppData%\subenum\` on Windows) and restored on next launch. +Leaving a numeric field blank uses its built-in default. + subenum interactive TUI
diff --git a/internal/tui/form.go b/internal/tui/form.go index fa4c679..b6e558a 100644 --- a/internal/tui/form.go +++ b/internal/tui/form.go @@ -550,11 +550,14 @@ func (m *formModel) validate() (formValues, string) { // The form only parses its text fields here; ranges and the resolver are // checked by scan.Options.Validate, the same validator the CLI uses (#80). - num := func(f int, name string, blank int) int { + // Blank values use the same defaults as remembered(). + num := func(f int, name string) int { s := strings.TrimSpace(text(f)) - if err != nil || s == "" { - keep(f, strconv.Itoa(blank)) - return blank + if err != nil { + return 0 + } + if s == "" { + s = formFields[f].def } n, perr := strconv.Atoi(s) if perr != nil { @@ -563,22 +566,22 @@ func (m *formModel) validate() (formValues, string) { keep(f, strconv.Itoa(n)) return n } - concurrency := num(fieldConcurrency, "Concurrency", 0) - timeout := num(fieldTimeout, "Timeout", 0) - attempts := num(fieldAttempts, "Attempts", 0) + concurrency := num(fieldConcurrency, "Concurrency") + timeout := num(fieldTimeout, "Timeout") + attempts := num(fieldAttempts, "Attempts") // Hit rate only matters in simulation mode, and depth only when // recursive is on; otherwise their fields must not block the scan. hitRate := scan.DefaultHitRate if m.shown(fieldHitRate) { - hitRate = num(fieldHitRate, "Hit rate", 0) + hitRate = num(fieldHitRate, "Hit rate") } depth := 1 if m.shown(fieldDepth) { - depth = num(fieldDepth, "Depth", 1) + depth = num(fieldDepth, "Depth") } - rate := num(fieldRate, "Rate", 0) // blank means unlimited - maxQueries := num(fieldMaxQueries, "Max queries", 0) // blank means unlimited - ratePerResolver := num(fieldRatePerResolver, formFields[fieldRatePerResolver].name(), 0) + rate := num(fieldRate, "Rate") // blank means unlimited + maxQueries := num(fieldMaxQueries, "Max queries") // blank means unlimited + ratePerResolver := num(fieldRatePerResolver, formFields[fieldRatePerResolver].name()) var maxDuration time.Duration // blank means unlimited, as -max-duration 0 if s := strings.TrimSpace(text(fieldMaxDuration)); err == nil && s != "" { var perr error diff --git a/internal/tui/form_test.go b/internal/tui/form_test.go index dc6eb9d..1fd51a9 100644 --- a/internal/tui/form_test.go +++ b/internal/tui/form_test.go @@ -45,8 +45,8 @@ func TestValidateNonPositiveConcurrency(t *testing.T) { } } -// Empty hit rate must be accepted when Simulate is OFF (it is never used), -// and rejected when Simulate is ON. +// Empty hit rate uses the default; explicit invalid values only matter +// when Simulate is ON. func TestValidateHitRateOnlyWhenSimulate(t *testing.T) { live := newFormModel(savedConfig{}) live.inputs[fieldDomain].SetValue("example.com") @@ -64,8 +64,8 @@ func TestValidateHitRateOnlyWhenSimulate(t *testing.T) { sim.inputs[fieldDomain].SetValue("example.com") sim.inputs[fieldHitRate].SetValue("") // blank hit rate sim.toggles[fieldSimulate] = true - if _, errStr := sim.validate(); errStr == "" { - t.Error("simulate mode should reject blank hit rate") + if vals, errStr := sim.validate(); errStr != "" || vals.HitRate != scan.DefaultHitRate { + t.Errorf("simulate mode with blank hit rate: rate %d, error %q", vals.HitRate, errStr) } sim.inputs[fieldHitRate].SetValue("500") // out of range @@ -74,6 +74,44 @@ func TestValidateHitRateOnlyWhenSimulate(t *testing.T) { } } +func TestValidateBlankNumericFieldsUseDefaults(t *testing.T) { + for _, field := range []int{fieldConcurrency, fieldTimeout, fieldAttempts, fieldHitRate, + fieldDepth, fieldRate, fieldMaxQueries, fieldRatePerResolver} { + t.Run(formFields[field].name(), func(t *testing.T) { + for _, blank := range []string{"", " \t "} { + m := newFormModel(savedConfig{Domain: "example.com", Simulate: true, Recursive: true}) + want, errStr := m.validate() + if errStr != "" { + t.Fatal(errStr) + } + m.inputs[field].SetValue(blank) + got, errStr := m.validate() + if errStr != "" { + t.Errorf("blank %q: %s", blank, errStr) + continue + } + if !reflect.DeepEqual(got.Options, want.Options) || !reflect.DeepEqual(got.saved, want.saved) { + t.Errorf("blank %q changed scan or saved defaults: got %+v, want %+v", blank, got, want) + } + } + }) + } +} + +func TestValidateExplicitInvalidNumericFields(t *testing.T) { + for _, field := range []int{fieldConcurrency, fieldTimeout, fieldAttempts, fieldHitRate} { + t.Run(formFields[field].name(), func(t *testing.T) { + for _, value := range []string{"0", "-1", "not-a-number"} { + m := newFormModel(savedConfig{Domain: "example.com", Simulate: true}) + m.inputs[field].SetValue(value) + if _, errStr := m.validate(); errStr == "" { + t.Errorf("explicit %q must still fail validation", value) + } + } + }) + } +} + func TestMoveFocusSkipsGatedFields(t *testing.T) { m := newFormModel(savedConfig{})