Skip to content

Commit e09bab8

Browse files
TMHSDigitalclaude
andcommitted
Parse -exclude patterns once per loop, not per name (#349)
scan.IsExcluded built the exclude scope from the patterns on every call, and each of its three callers called it once per name: nextOffset for subenum mcp (up to 1,000 patterns times 50,000 words per call), the -dry-run candidate count and -diff's list of missing names. IsExcluded is replaced by scan.Excluder, which parses the patterns once and returns the scope's test; each caller builds one before its loop. TestScopeMatching checks that it applies the same rules. The other half of #349, an opt-out of the library's inconclusive-name list for subenum mcp, adds to pkg/subenum's API and is left open. Refs #349 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1278396 commit e09bab8

5 files changed

Lines changed: 19 additions & 7 deletions

File tree

‎internal/cli/diff.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,9 @@ func (d *differ) missingNames(targets, exclude []string) []string {
291291
d.mu.Lock()
292292
defer d.mu.Unlock()
293293
var out []string
294+
excluded := scan.Excluder(exclude)
294295
for name := range d.previous {
295-
if _, ok := d.current[name]; ok || scan.IsExcluded(exclude, name) {
296+
if _, ok := d.current[name]; ok || excluded(name) {
296297
continue
297298
}
298299
for _, t := range targets {

‎internal/cli/dryrun.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ func (s *session) dryRun() int {
4444
defer dns.CloseIdleConnections(resolver)
4545
plans := make([]dryRunTarget, 0, len(s.targets))
4646
failed := false
47+
excluded := scan.Excluder(s.in.excludes)
4748
for _, target := range s.targets {
4849
entries, duplicates, skipped := s.words.For(target)
4950
p := dryRunTarget{Domain: target, Duplicates: duplicates, Skipped: skipped, PreflightOK: true}
5051
for _, e := range entries {
51-
if len(s.in.excludes) > 0 && scan.IsExcluded(s.in.excludes, e+"."+target) {
52+
if len(s.in.excludes) > 0 && excluded(e+"."+target) {
5253
p.Excluded++
5354
continue
5455
}

‎internal/cli/mcp_tools.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,9 @@ func nextOffset(cfg subenum.Config, stats subenum.Stats, offset int) int {
383383
return 0
384384
}
385385
tested := 0
386+
excluded := scan.Excluder(cfg.Exclude)
386387
for i, word := range cfg.Words {
387-
if scan.IsExcluded(cfg.Exclude, word+"."+cfg.Domain) {
388+
if excluded(word + "." + cfg.Domain) {
388389
continue
389390
}
390391
if tested == cfg.MaxQueries {

‎internal/scan/scope.go‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ func parentOf(name string) string {
8989
return ""
9090
}
9191

92-
// IsExcluded reports whether name is out of scope under the -exclude
93-
// patterns, using the same rules as a scan.
94-
func IsExcluded(patterns []string, name string) bool {
95-
return newScope(patterns).excluded(name)
92+
// Excluder returns a test of whether a name is out of scope under the
93+
// -exclude patterns, using the same rules as a scan. The patterns are parsed
94+
// once, so a caller checking many names builds one Excluder (#349).
95+
func Excluder(patterns []string) func(name string) bool {
96+
return newScope(patterns).excluded
9697
}

‎internal/scan/scope_test.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ func TestScopeMatching(t *testing.T) {
2929
if (*scope)(nil).excluded("x.example.com") {
3030
t.Error("nil scope excluded a name")
3131
}
32+
// Excluder applies the same rules, from patterns parsed once (#349).
33+
excluded := Excluder([]string{"VPN.example.com.", "*.dev.example.com"})
34+
if !excluded("vpn.example.com") || !excluded("api.dev.example.com") || excluded("dev.example.com") {
35+
t.Error("Excluder does not match the scope's rules")
36+
}
37+
if Excluder(nil)("www.example.com") {
38+
t.Error("Excluder with no patterns excluded a name")
39+
}
3240
if err := ValidateExcludes([]string{"*.ok.example.com", "bad pattern"}); err == nil || !strings.Contains(err.Error(), "bad pattern") {
3341
t.Errorf("ValidateExcludes accepted an invalid pattern: %v", err)
3442
}

0 commit comments

Comments
 (0)