]> git.eshelyaron.com Git - emacs.git/commitdiff
Make eww work better on Tramp HTML
authorLars Ingebrigtsen <larsi@gnus.org>
Sun, 20 Feb 2022 15:08:45 +0000 (16:08 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 20 Feb 2022 15:14:05 +0000 (16:14 +0100)
* lisp/net/eww.el (eww-open-file): Use it.
(eww-browse-url): Ditto.

* lisp/net/shr.el (shr-expand-url): Allow loading relative Tramp
files if we're reading from a file:// document.

* lisp/url/url-file.el (url-allow-non-local-files): New user option
(bug#40425).

lisp/net/eww.el
lisp/net/shr.el
lisp/url/url-file.el

index cfebb108a5b3486fb14f980c1ddb97db08b48345..700a6c3e82fb09d3bfab9e3df7701fd66a560bb6 100644 (file)
@@ -32,6 +32,7 @@
 (require 'thingatpt)
 (require 'url)
 (require 'url-queue)
+(require 'url-file)
 (require 'xdg)
 (eval-when-compile (require 'subr-x))
 
@@ -487,15 +488,11 @@ killed after rendering."
 (defun eww-open-file (file)
   "Render FILE using EWW."
   (interactive "fFile: ")
-  (eww (concat "file://"
-              (and (memq system-type '(windows-nt ms-dos))
-                   "/")
-              (expand-file-name file))
-       nil
-       ;; The file name may be a non-local Tramp file.  The URL
-       ;; library doesn't understand these file names, so use the
-       ;; normal Emacs machinery to load the file.
-       (eww--file-buffer file)))
+  (let ((url-allow-non-local-files t))
+    (eww (concat "file://"
+                (and (memq system-type '(windows-nt ms-dos))
+                     "/")
+                (expand-file-name file)))))
 
 (defun eww--file-buffer (file)
   (with-current-buffer (generate-new-buffer " *eww file*")
@@ -1207,7 +1204,8 @@ instead of `browse-url-new-window-flag'."
       (format "*eww-%s*" (url-host (url-generic-parse-url
                                     (eww--dwim-expand-url url))))))
     (eww-mode))
-  (eww url))
+  (let ((url-allow-non-local-files t))
+    (eww url)))
 
 (defun eww-back-url ()
   "Go to the previously displayed page."
index 6e0af06bed1d1b08929c709320e1f8a6e1b4b2aa..2a4fa9ceb0c903cad4a4228e04cd9febbb89caa9 100644 (file)
@@ -877,8 +877,10 @@ size, and full-buffer size."
         ;; A link to an anchor.
         (concat (nth 3 base) url))
        (t
-        ;; Totally relative.
-        (url-expand-file-name url (concat (car base) (cadr base))))))
+        ;; Totally relative.  Allow Tramp file names if we're
+        ;; rendering a file:// URL.
+         (let ((url-allow-non-local-files (equal (nth 2 base) "file")))
+          (url-expand-file-name url (concat (car base) (cadr base)))))))
 
 (defun shr-ensure-newline ()
   (unless (bobp)
index 31e5c07234c7ad5280dea3172a5746fbe406c9f8..60a79425a3f078ef399089a9eba9a410d75dd34e 100644 (file)
 (require 'url-dired)
 (declare-function mm-disable-multibyte "mm-util" ())
 
+(defvar url-allow-non-local-files nil
+  "If non-nil, allow URL to fetch non-local files.
+By default, this is not allowed, since that would allow rendering
+HTML to fetch files on other systems if given a <img
+src=\"/ssh:host...\"> element, which can be disturbing.")
+
 (defconst url-file-default-port 21 "Default FTP port.")
 (defconst url-file-asynchronous-p t "FTP transfers are asynchronous.")
 (defalias 'url-file-expand-file-name 'url-default-expander)
@@ -111,7 +117,8 @@ to them."
                          (memq system-type '(ms-dos windows-nt)))
                     (substring file 1))
                    ;; file: URL with a file:/bar:/foo-like spec.
-                   ((string-match "\\`/[^/]+:/" file)
+                   ((and (not url-allow-non-local-files)
+                          (string-match "\\`/[^/]+:/" file))
                     (concat "/:" file))
                    (t
                     file))))