From 7bad11a4a7df030c9622cf7732e6a673089d04f8 Mon Sep 17 00:00:00 2001 From: Ryan Smith Date: Wed, 26 Mar 2025 18:17:31 -0700 Subject: [PATCH] Allow comments in exclude list This change allows for comments in the exclude list using the `#` symbol. The `#` symbol on a line and everything after it is ignored when parsing the exclude list. --- internal/threatfeed/feed.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/threatfeed/feed.go b/internal/threatfeed/feed.go index 9064120..dd6d5f6 100644 --- a/internal/threatfeed/feed.go +++ b/internal/threatfeed/feed.go @@ -118,7 +118,8 @@ loop: // parseExcludeList reads IP addresses and CIDR ranges from a file. Each line // should contain an IP address or CIDR. It returns a map of the unique IPs and -// a slice of the CIDR ranges found in the file. +// a slice of the CIDR ranges found in the file. The file may include comments +// using "#". The "#" symbol on a line and everything after is ignored. func parseExcludeList(filepath string) (map[string]struct{}, []*net.IPNet, error) { if len(filepath) == 0 { return map[string]struct{}{}, []*net.IPNet{}, nil @@ -137,6 +138,12 @@ func parseExcludeList(filepath string) (map[string]struct{}, []*net.IPNet, error scanner := bufio.NewScanner(f) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) + + // Remove comments from text. + if i := strings.Index(line, "#"); i != -1 { + line = strings.TrimSpace(line[:i]) + } + if len(line) > 0 { if _, ipnet, err := net.ParseCIDR(line); err == nil { cidr = append(cidr, ipnet)