fix: support comma-separated inputs in list file (-l option)#963
fix: support comma-separated inputs in list file (-l option)#963zhaog100 wants to merge 1 commit intoprojectdiscovery:mainfrom
Conversation
The -u option correctly handles comma-separated targets via CommaSeparatedStringSliceOptions, but the -l option treated each line as a single target. This change splits each line by comma, matching the behavior of -u.
Neo - PR Security ReviewNo security issues found Highlights
Hardening Notes
Comment |
WalkthroughThe 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)
📝 Coding Plan
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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/runner/runner.go`:
- Around line 443-447: When splitting comma-separated targets in the input
handling loop, trim whitespace from each token before calling r.processInputItem
so tokens like " 192.168.2.0/24" are normalized (use strings.TrimSpace on each
item); additionally propagate and return any errors encountered while scanning
files instead of swallowing them—update the code paths that call file scanning
(the scanner loop around r.processInputItem and any file-read helpers) to
capture scan errors and return a wrapped error using the ProjectDiscovery
utils/errors package and consistent logging with gologger (reference
r.processInputItem and the file scan/scan loop) so failures are surfaced to the
caller.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9216d0b8-a6f1-48e8-9185-7c4b7fde39be
📒 Files selected for processing (1)
internal/runner/runner.go
| for _, item := range strings.Split(text, ",") { | ||
| if item != "" { | ||
| r.processInputItem(item, inputs) | ||
| } | ||
| } |
There was a problem hiding this comment.
Trim comma-split targets and surface scan failures.
Line 443 splits by comma but keeps surrounding whitespace, so entries like 192.168.1.0/24, 192.168.2.0/24 still send an invalid leading-space token to processInputItem. Also, file scan errors are not returned, so input processing can fail silently.
💡 Proposed fix
scanner := bufio.NewScanner(file)
for scanner.Scan() {
- text := scanner.Text()
- if text != "" {
- for _, item := range strings.Split(text, ",") {
- if item != "" {
- r.processInputItem(item, inputs)
- }
- }
- }
+ text := strings.TrimSpace(scanner.Text())
+ if text == "" {
+ continue
+ }
+ for _, item := range strings.Split(text, ",") {
+ item = strings.TrimSpace(item)
+ if item == "" {
+ continue
+ }
+ r.processInputItem(item, inputs)
+ }
}
+ if err := scanner.Err(); err != nil {
+ return errkit.Wrap(err, "could not read input file")
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| for _, item := range strings.Split(text, ",") { | |
| if item != "" { | |
| r.processInputItem(item, inputs) | |
| } | |
| } | |
| scanner := bufio.NewScanner(file) | |
| for scanner.Scan() { | |
| text := strings.TrimSpace(scanner.Text()) | |
| if text == "" { | |
| continue | |
| } | |
| for _, item := range strings.Split(text, ",") { | |
| item = strings.TrimSpace(item) | |
| if item == "" { | |
| continue | |
| } | |
| r.processInputItem(item, inputs) | |
| } | |
| } | |
| if err := scanner.Err(); err != nil { | |
| return errkit.Wrap(err, "could not read input file") | |
| } |
🤖 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 - 447, When splitting
comma-separated targets in the input handling loop, trim whitespace from each
token before calling r.processInputItem so tokens like " 192.168.2.0/24" are
normalized (use strings.TrimSpace on each item); additionally propagate and
return any errors encountered while scanning files instead of swallowing
them—update the code paths that call file scanning (the scanner loop around
r.processInputItem and any file-read helpers) to capture scan errors and return
a wrapped error using the ProjectDiscovery utils/errors package and consistent
logging with gologger (reference r.processInputItem and the file scan/scan loop)
so failures are surfaced to the caller.
Summary
Fixes #859
The
-uoption correctly handles comma-separated targets (e.g.,./tlsx -u 192.168.1.0/24,192.168.2.0/24) viaCommaSeparatedStringSliceOptions, but the-loption treated each line as a single target.Changes
internal/runner/runner.goto split each line by comma when reading from the input list file, matching the behavior of the-uoption.Testing
go build ./...Summary by CodeRabbit