* filter: skip comment lines starting with '#'

Fix #771, filter skips comment lines starting with '#'.

Handle exclamation inline comments.

Refactor for correct logic flow.

Split out hashtag comment logic from exclamation.

Remove trailing whitespace.
This commit is contained in:
DannyHinshaw 2020-04-30 10:19:10 -04:00 committed by Simon Zolin
parent f250fc16a2
commit b034e25b26
2 changed files with 3 additions and 0 deletions

View File

@ -478,6 +478,8 @@ func (f *Filtering) parseFilterContents(file io.Reader) (int, uint32, string) {
name = m[0][1] name = m[0][1]
seenTitle = true seenTitle = true
} }
} else if line[0] == '#' {
continue
} else { } else {
rulesCount++ rulesCount++
} }

View File

@ -14,6 +14,7 @@ import (
func testStartFilterListener() net.Listener { func testStartFilterListener() net.Listener {
http.HandleFunc("/filters/1.txt", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/filters/1.txt", func(w http.ResponseWriter, r *http.Request) {
content := `||example.org^$third-party content := `||example.org^$third-party
# Inline comment example
||example.com^$third-party ||example.com^$third-party
0.0.0.0 example.com 0.0.0.0 example.com
` `