]> git.ipfire.org Git - dbl.git/commitdiff
sources: Fail if we are trying to import some HTML
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 2 Mar 2026 17:17:49 +0000 (17:17 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 2 Mar 2026 17:17:49 +0000 (17:17 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dbl/sources.py

index 8f9bfb4af92d87a51ee1d4f0e64ff5b3a2d94456..10948864b2e6bb3c7ccf3b0e33fa0332c03acea2 100644 (file)
@@ -247,7 +247,14 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True):
 
                                                        # Detect the format if still unknown
                                                        if format is None:
-                                                               format = self._detect_format(line)
+                                                               try:
+                                                                       format = self._detect_format(line)
+
+                                                               # Log a warning if we have detected some invalid format
+                                                               except Exception as e:
+                                                                       log.warning("Format detection failed for %s: %s" % (self.url, e))
+
+                                                                       return False
 
                                                        # Process the line according to its format
                                                        match format:
@@ -454,6 +461,10 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True):
                elif util.is_fqdn(line):
                        return Format.PLAIN
 
+               # Fail if we have received a HTML document
+               if line.startswith("<"):
+                       raise ValueError("Source seems to be in HTML format")
+
                # The format is (still?) unknown
                return None