Repository navigation
Refactor loadFromFile to use bufio.Scanner - #1791
Conversation
Walkthrough
ChangesResolver File Loading and Domain Preprocessing
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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)
pkg/runner/util.go (1)
11-28: 💤 Low valueHandle the
f.Close()error (or explicitly discard it) to satisfy errcheck.golangci-lint (
errcheck) flags the deferredf.Close()on line 16. For a read-only file the actual risk is negligible, but this will likely fail the CI lint gate. The simplest fix is an explicit discard.♻️ Proposed tweak
- defer f.Close() + defer func() { _ = f.Close() }()🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/runner/util.go` around lines 11 - 28, The deferred file close in loadFromFile currently ignores the returned error which trips errcheck; update the defer to explicitly discard or handle the error from f.Close() (for example use defer func(){ _ = f.Close() }() or capture and log/return it) so that the close error is not ignored; change the defer f.Close() inside loadFromFile accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/runner/util.go`:
- Around line 11-28: The deferred file close in loadFromFile currently ignores
the returned error which trips errcheck; update the defer to explicitly discard
or handle the error from f.Close() (for example use defer func(){ _ = f.Close()
}() or capture and log/return it) so that the close error is not ignored; change
the defer f.Close() inside loadFromFile accordingly.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/runner/util.go (1)
26-43: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueScheme/path stripping logic looks correct.
Order of operations is sound: normalization lowercases first, so
TrimPrefixreliably matches mixed-case schemes (e.g.,HTTPS://), andIndexAnycorrectly truncates at the first path/query/fragment delimiter after scheme removal. Test cases inutil_test.gocorroborate the expected behavior for scheme, path, query, fragment, and IP normalization.One optional improvement: hardcoding two
TrimPrefixcalls works today but doesn't scale if additional schemes (e.g.,ftp://) need support later.♻️ Optional refactor for extensibility
- s = strings.TrimPrefix(s, "https://") - s = strings.TrimPrefix(s, "http://") + for _, scheme := range []string{"https://", "http://"} { + s = strings.TrimPrefix(s, scheme) + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/runner/util.go` around lines 26 - 43, The current scheme/path stripping in preprocessDomain works, but it is hardcoded to only handle http and https. Refactor the trimming logic in preprocessDomain to use a more extensible scheme-removal approach so future schemes can be supported without adding more TrimPrefix calls, while preserving the existing normalization and path/query/fragment truncation behavior verified by util_test.go.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/runner/util.go`:
- Around line 26-43: The current scheme/path stripping in preprocessDomain
works, but it is hardcoded to only handle http and https. Refactor the trimming
logic in preprocessDomain to use a more extensible scheme-removal approach so
future schemes can be supported without adding more TrimPrefix calls, while
preserving the existing normalization and path/query/fragment truncation
behavior verified by util_test.go.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3156e3f5-83b9-4d90-8986-013bcf2a59b5
📒 Files selected for processing (2)
pkg/runner/util.gopkg/runner/util_test.go
subfinder 2.15.0 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## What's Changed ### 🎉 New Features * Added shodanct passive source by @dogancanbakir in projectdiscovery/subfinder#1796 * Added Option `-vR`, `-virustotal-res` for VirusTotal source by @Bundy01 in projectdiscovery/subfinder#1719 * Added machine-readable source listing with `-ls -oJ` by @Gerijacki in projectdiscovery/subfinder#1812 ### 🐞 Bug Fixes * Fixed source leaks by @Mzack9999 in projectdiscovery/subfinder#1801 * Fixed drain source channels on cancel so source goroutines exit instead of leaking on a blocked send by @Mzack9999 in projectdiscovery/subfinder#1799 * Fixed crtsh's query by dropping unused certificate metadata from SQL query by @ChrisJr404 in projectdiscovery/subfinder#1787 * Fixed VirusTotal source by capping pagination and providing clearer 429 message by @ChrisJr404 in projectdiscovery/subfinder#1788 * Fixed Anubis source by switching subdomain API to anubisdb.com by @jatinder14 in projectdiscovery/subfinder#1815 ### Other Changes * Fixed lint issues by @dogancanbakir in projectdiscovery/subfinder#1820 * Refactored loadFromFile to use bufio.Scanner by @nandaanomi in projectdiscovery/subfinder#1791 ## New Contributors * @ChrisJr404 made their first contribution in projectdiscovery/subfinder#1787 * @Bundy01 made their first contribution in projectdiscovery/subfinder#1719 * @nandaanomi made their first contribution in projectdiscovery/subfinder#1791 * @jatinder14 made their first contribution in projectdiscovery/subfinder#1815 * @Gerijacki made their first contribution in projectdiscovery/subfinder#1812 **Full Changelog**: https://github.com/projectdiscovery/subfinder/compare/v2.14.0...v2.15.0</pre> <p>View the full release notes at <a href="https://github.com/projectdiscovery/subfinder/releases/tag/v2.15.0">https://github.com/projectdiscovery/subfinder/releases/tag/v2.15.0</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!16007
Proposed changes
Fixes #1790
Two bugs fixed in
pkg/runner/util.go:1. Replaced
fileutil.ReadFile(channel-based, goroutine errors not propagatable) withbufio.Scanner+os.Open.scanner.Err()is now returned so any I/O error during mid-read is surfaced to the caller instead of silently producing a partial list.2.
preprocessDomainnow stripshttps://andhttp://prefixes and truncates at the first/,?, or#. This prevents malformed entries likehttps://8.8.8.8in resolver/domain list files from silently failing inside dnsx.Minor: added
make([]string, 0, 64)to reduce reallocs on large input files.Proof
echo "https://8.8.8.8" > resolvers.txt
subfinder -d example.com -rL resolvers.txt -v
Before: resolver passed as-is, silently unused, no error shown.
After: entry normalized to
8.8.8.8, resolver used correctly.Checklist
Summary by CodeRabbit
http://andhttps://prefixes and extracts only the host portion by trimming paths, queries, and fragments for more consistent normalization and matching.