From: Michael Tremer Date: Fri, 2 Jan 2026 13:21:26 +0000 (+0000) Subject: sources: Always strip any comments X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dae5d75a7486fb4852d820cd574b60c5aae23f0e;p=dbl.git sources: Always strip any comments So far it looks like all file formats are using # to separate any comments. Therefore we can strip anything away very early on. Signed-off-by: Michael Tremer --- diff --git a/src/dnsbl/sources.py b/src/dnsbl/sources.py index 9e2700d..3a41dcf 100644 --- a/src/dnsbl/sources.py +++ b/src/dnsbl/sources.py @@ -229,6 +229,13 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True): for line in f: line = line.rstrip() + # Strip any comments + line, hashtag, comment = line.partition("#") + + # Skip the line if it is empty + if not line: + continue + # Detect the format if still unknown if format is None: format = self._detect_format(line) @@ -420,9 +427,6 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True): """ Parses a line of a hosts file. """ - # Strip any comments - line, _, comment = line.partition("#") - for prefix in HOST_PREFIXES: if line.startswith(prefix): return line.removeprefix(prefix) @@ -434,9 +438,7 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True): """ Parses a plain list of domains """ - domain, _, comment = line.partition("#") - - return domain + return line def add_domains(self, _domains): """