fix: handle comma-separated entries in -l/--list input file#922
fix: handle comma-separated entries in -l/--list input file#922Bushi-gg wants to merge 1 commit intoprojectdiscovery:mainfrom
Conversation
…ojectdiscovery#859) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Neo Security AuditNo security issues found Comment |
WalkthroughThe input parsing in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/runner/runner.go (1)
441-448: Deduplicate comma-splitting logic for file/stdin inputs.The same split/trim/skip logic appears twice; a small helper keeps future tweaks consistent in both paths.
♻️ Suggested refactor
func (r *Runner) normalizeAndQueueInputs(inputs chan taskInput) error { + normalizeLine := func(text string) { + for _, item := range strings.Split(text, ",") { + item = strings.TrimSpace(item) + if item != "" { + r.processInputItem(item, inputs) + } + } + } // Process Normal Inputs for _, text := range r.options.Inputs { r.processInputItem(text, inputs) } @@ scanner := bufio.NewScanner(file) for scanner.Scan() { text := scanner.Text() if text != "" { - for _, item := range strings.Split(text, ",") { - item = strings.TrimSpace(item) - if item != "" { - r.processInputItem(item, inputs) - } - } + normalizeLine(text) } } @@ scanner := bufio.NewScanner(os.Stdin) for scanner.Scan() { text := scanner.Text() if text != "" { - for _, item := range strings.Split(text, ",") { - item = strings.TrimSpace(item) - if item != "" { - r.processInputItem(item, inputs) - } - } + normalizeLine(text) } } return nil }Also applies to: 456-462
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/runner/runner.go` around lines 441 - 448, The comma-split/trim/skip loop used to feed r.processInputItem from scanner.Text (and the duplicate at lines 456-462) should be extracted into a small helper to avoid duplication; create a method like splitAndProcessInputItems(text string, inputs *InputType) (or a package-level helper if appropriate) that does strings.Split(text, ","), strings.TrimSpace per item, skips empty items, and calls r.processInputItem(item, inputs); then replace both inline loops with calls to this helper, keeping the original scanner.Text usage and r.processInputItem calls intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/runner/runner.go`:
- Around line 441-448: The comma-split/trim/skip loop used to feed
r.processInputItem from scanner.Text (and the duplicate at lines 456-462) should
be extracted into a small helper to avoid duplication; create a method like
splitAndProcessInputItems(text string, inputs *InputType) (or a package-level
helper if appropriate) that does strings.Split(text, ","), strings.TrimSpace per
item, skips empty items, and calls r.processInputItem(item, inputs); then
replace both inline loops with calls to this helper, keeping the original
scanner.Text usage and r.processInputItem calls intact.
Fix
Resolves #859 — the
-l/--listflag now handles comma-separated entries within a single line, matching the behavior of-u./claim #859
Problem
When using
-l filename.txtwhere the file contains comma-separated prefixes on a single line (e.g.192.168.1.0/24,192.168.2.0/24,192.168.3.0/24), tlsx tried to use the entire comma-separated string as a single host, resulting in:Changes
In
normalizeAndQueueInputs()(internal/runner/runner.go), lines read from the input file and stdin are now split by comma before processing:strings.Splitreturns one-element slice)strings.TrimSpaceTesting
go build ./...passes-uhandles comma-separated inputs viagoflags.CommaSeparatedStringSliceOptionsSummary by CodeRabbit