fix: split comma-separated entries when reading from file input#912
fix: split comma-separated entries when reading from file input#912jcrewfare wants to merge 2 commits intoprojectdiscovery:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 WalkthroughThe change adds a helper to split comma-separated items on each input line and uses it in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 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)
443-448: Extract the repeated split-trim-process block into a helper to avoid duplication.The identical four-line loop appears verbatim in both the
InputListand stdin branches. Extracting it reduces future drift risk.♻️ Proposed refactor
Add a small helper above
normalizeAndQueueInputs:+// processLine splits a comma-separated input line and queues each non-empty item. +func (r *Runner) processLine(text string, inputs chan taskInput) { + for _, item := range strings.Split(text, ",") { + item = strings.TrimSpace(item) + if item != "" { + r.processInputItem(item, inputs) + } + } +}Then replace both duplicated blocks:
for scanner.Scan() { text := scanner.Text() if text != "" { - for _, item := range strings.Split(text, ",") { - item = strings.TrimSpace(item) - if item != "" { - r.processInputItem(item, inputs) - } - } + r.processLine(text, inputs) } }(Apply the same diff to both the
InputListand stdin scanner loops.)Also applies to: 457-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 443 - 448, The comma-split/trim/process loop is duplicated in normalizeAndQueueInputs (both the InputList branch and the stdin scanner branch); extract it into a helper method on Runner (e.g., func (r *Runner) processLine(text string, inputs chan taskInput)) that performs strings.Split, strings.TrimSpace, filters empty strings and calls r.processInputItem for each item, then replace both duplicated four-line blocks with calls to r.processLine(text, inputs).
🤖 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 443-448: The comma-split/trim/process loop is duplicated in
normalizeAndQueueInputs (both the InputList branch and the stdin scanner
branch); extract it into a helper method on Runner (e.g., func (r *Runner)
processLine(text string, inputs chan taskInput)) that performs strings.Split,
strings.TrimSpace, filters empty strings and calls r.processInputItem for each
item, then replace both duplicated four-line blocks with calls to
r.processLine(text, inputs).
|
Thank you for the contribution! This issue has been resolved by #953 which was merged with the same approach (splitting comma-separated entries in file and stdin input) along with a dedicated test. Closing as superseded. |
Fixes #859
The
-uflag correctly splits comma-separated values viaCommaSeparatedStringSliceOptions, but-land stdin pass entire lines toprocessInputItemwithout splitting.Added
strings.Split(text, ",")to both the file reader and stdin reader innormalizeAndQueueInputs, matching the behavior of-u.Before:
echo '192.168.1.0/24,192.168.2.0/24' > targets.txt
tlsx -l targets.txt # treats entire line as one target
After:
tlsx -l targets.txt # splits and processes each entry separately
Summary by CodeRabbit
Release Notes