]> git.phdru.name Git - bookmarks_db.git/commitdiff
Fix(robots): Do not parse empty strings
authorOleg Broytman <phd@phdru.name>
Fri, 17 Nov 2023 23:55:10 +0000 (02:55 +0300)
committerOleg Broytman <phd@phdru.name>
Fri, 17 Nov 2023 23:55:10 +0000 (02:55 +0300)
Some sites return empty "html" that consist only of white spaces.
Strip them to get really empty string.

Robots/bkmk_robot_base.py

index d8877c6f41c6b6f30c8d8ba4b8dbcec396e6c02b..52d6b563f1056c9ffe29a08299d59084d248be4e 100644 (file)
@@ -149,8 +149,9 @@ class robot_base(Robot):
                         if content_type.startswith(ctype):
                             is_html = True
                             break
-                    if content and is_html:
-                        parser = parse_html(content, charset, self.log)
+                    content_stripped = content.strip()
+                    if content_stripped and is_html:
+                        parser = parse_html(content_stripped, charset, self.log)
                         if parser:
                             bookmark.real_title = parser.title
                             icon = parser.icon
@@ -246,7 +247,7 @@ class robot_base(Robot):
                                                   % (url, timeout)
                                                   )
 
-                    if not content:
+                    if not content_stripped:
                         self.log("   empty response, no content")
                     if not is_html:
                         self.log("   not html")