Skip to content

Commit

Permalink
fix: ignore end of line comments when parsing lists
Browse files Browse the repository at this point in the history
  • Loading branch information
ThinkChaos committed Feb 7, 2023
1 parent 101e2c5 commit 6548d15
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lists/list_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ func processLine(line string) string {
return ""
}

// remove end of line comment
if idx := strings.IndexRune(line, '#'); idx != -1 {
line = line[:idx]
}

if parts := strings.Fields(line); len(parts) > 0 {
host := parts[len(parts)-1]

Expand Down
15 changes: 15 additions & 0 deletions lists/list_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@ var _ = Describe("ListCache", func() {
Expect(group).Should(Equal("gr1"))
})
})
When("file has end of line comment", func() {
It("should still parse the domain", func() {
lists := map[string][]string{
"gr1": {"inlinedomain1.com#a comment\n"},
}

sut, err := NewListCache(ListCacheTypeBlacklist, lists, 0, NewDownloader(),
defaultProcessingConcurrency, false)
Expect(err).Should(Succeed())

found, group := sut.Match("inlinedomain1.com", []string{"gr1"})
Expect(found).Should(BeTrue())
Expect(group).Should(Equal("gr1"))
})
})
When("inline regex content is defined", func() {
It("should match", func() {
lists := map[string][]string{
Expand Down

0 comments on commit 6548d15

Please sign in to comment.