]> git.ipfire.org Git - dbl.git/commitdiff
sources: Always strip any comments
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 2 Jan 2026 13:21:26 +0000 (13:21 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 2 Jan 2026 13:21:26 +0000 (13:21 +0000)
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 <michael.tremer@ipfire.org>
src/dnsbl/sources.py

index 9e2700d820e49883a414dc72aa02f3f12290b725..3a41dcf4dd8c1c6c84b5e5df8b8413cb8e931f9c 100644 (file)
@@ -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):
                """