From e701649fd0463fc08cfc823c56cca9e7f37bd82d Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 2 Jul 2025 14:32:28 -0700 Subject: [PATCH] Retain the tag when making a page in EWW document readable 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 | 2 +- test/lisp/net/eww-tests.el | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 7f7dfa5cfc9..f321ff712f2 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -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 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 diff --git a/test/lisp/net/eww-tests.el b/test/lisp/net/eww-tests.el index 18cbd272991..e9cfde4243a 100644 --- a/test/lisp/net/eww-tests.el +++ b/test/lisp/net/eww-tests.el @@ -39,6 +39,7 @@ body.") "" "Welcome to my home page" "" + "" "" "This is an uninteresting sentence." "
" eww-test--lots-of-words "
" @@ -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 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 -- 2.39.5