Subject: Re: bug#73133: 29.2; EWW fails to render some webpages

From: Sebastián Monía <[email-masked]>
Date: Thu, 24 Oct 2024 13:13:26 -0400

Sebastián Monía <[email-masked]> writes:
> Jim Porter <[email-masked]> writes:
>> Thoughts on just simplifying to checking for "<!doctype html"? That
>> way, we'd also guess "text/html" for all the (mostly obsolete) HTML
>> doctypes here: <https://www.w3.org/QA/2002/04/valid-dtd-list.html>.
>
> It sounds like a good idea, can provide a patch in a couple days (maybe
> tomorrow). That leaves some time for dissenting voices to express any
> concerns with this approach.

Attached a patch with the corrections mentioned so far.

>From 952930c78dcfe7e4bb3a32504805239ae32073e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebasti=C3=A1n=20Mon=C3=ADa?=
 <[email-masked]>
Date: Thu, 24 Oct 2024 13:09:11 -0400
Subject: [PATCH] More lax doctype check in EWW (bug#73133)

The regexp to match doctype tags was simplified and will match
more legacy entries; also correct binding of case-fold-search.

* lisp/net/eww.el (eww--html buffer-list): Update function.
---
 lisp/net/eww.el | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 7bbbeadaedd..71e4d720b74 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -660,15 +660,14 @@ eww--html-if-doctype
   "Return \"text/html\" if RESPONSE-BUFFER has an HTML doctype declaration.
 HEADERS is unused."
   ;; https://html.spec.whatwg.org/multipage/syntax.html#the-doctype
-  (let ((case-fold-search t)
-        (target
-         "<!doctype +html *\\(>\\|system +\\(\\\"\\|'\\)+about:legacy-compat\\)"))
-    (with-current-buffer response-buffer
-      (goto-char (point-min))
-      ;; match basic <!doctype html> and also legacy variants as
-      ;; specified in link above
-      (when (re-search-forward target nil t)
-        "text/html"))))
+  (with-current-buffer response-buffer
+    (let ((case-fold-search t))
+      (save-excursion
+        (goto-char (point-min))
+        ;; match basic <!doctype html> and also legacy variants as
+        ;; specified in link above - being purposely lax about it
+        (when (re-search-forward "<!doctype html" nil t)
+          "text/html")))))
 
 (defun eww--rename-buffer ()
   "Rename the current EWW buffer.
-- 
2.45.2.windows.1

-- 
Sebastián Monía
https://site.sebasmonia.com/