]> git.eshelyaron.com Git - emacs.git/commitdiff
Retain the <base> tag when making a page in EWW document readable
authorSteven Allen <steven@stebalien.com>
Wed, 2 Jul 2025 21:32:28 +0000 (14:32 -0700)
committerEshel Yaron <me@eshelyaron.com>
Wed, 23 Jul 2025 20:14:09 +0000 (22:14 +0200)
The base tag is necessary to correctly resolve relative links.

* lisp/net/eww.el (eww-readable-dom): Retain the base tag in addition to
the title/link tags.  (Bug#78948)
* test/lisp/net/eww-tests.el (eww-test--wordy-page): Add a base tag.
(eww-test/readable/default-readable): Test that the base tag is retained.

(cherry picked from commit f10bf71151b7f5d0e1d7d183c11261b257d4d022)

lisp/net/eww.el
test/lisp/net/eww-tests.el

index 7f7dfa5cfc926cfc55ad5bf05da1d6f6e3a2b8cf..f321ff712f219d76bedeb6400a18af6f9b02c436 100644 (file)
@@ -1199,7 +1199,7 @@ non-nil, don't actually compute a score; just call the callback."
          ;; "previous" pages.  NOTE: We could probably filter out
          ;; stylesheet <link> tags here, though it doesn't really matter
          ;; since we don't *do* anything with stylesheets...
-         (when (memq (dom-tag node) '(title link))
+         (when (memq (dom-tag node) '(title link base))
            ;; Copy the node, but not any of its (non-text) children.
            ;; This way, we can ensure that we don't include a node
            ;; directly in our list in addition to as a child of some
index 18cbd2729913d64aae94247df00142a1f9a4232c..e9cfde4243a1e85c1e4623682b0a3f314da0591c 100644 (file)
@@ -39,6 +39,7 @@ body.")
           "<head>"
           "<title>Welcome to my home page</title>"
           "<link rel=\"home\" href=\"somewhere.invalid\">"
+          "<base href=\"/foo/\">"
           "</head><body>"
           "<a>This is an uninteresting sentence.</a>"
           "<div>" eww-test--lots-of-words "</div>"
@@ -251,9 +252,13 @@ This sets `eww-before-browse-history-function' to
       (eww "example.invalid")
       ;; Make sure EWW uses "readable" mode.
       (should (plist-get eww-data :readable))
-      ;; Make sure the page include the <title> and <link> nodes.
+      ;; Make sure the page include the <title>, <link>, and <base> nodes.
       (should (equal (plist-get eww-data :title) "Welcome to my home page"))
-      (should (equal (plist-get eww-data :home) "somewhere.invalid")))))
+      (should (equal (plist-get eww-data :home) "somewhere.invalid"))
+      (let* ((html (dom-child-by-tag (plist-get eww-data :dom) 'html))
+             (base-tags (dom-by-tag html 'base)))
+        (should (length= base-tags 1))
+        (should (equal (dom-attr (car base-tags) 'href) "/foo/"))))))
 
 (provide 'eww-tests)
 ;; eww-tests.el ends here