From: LdBeth <andpuke@foxmail.com>
To: 52594@debbugs.gnu.org
Subject: bug#52594: [PATCH] Add image whiltelist to shr.el
Date: Sat, 18 Dec 2021 16:22:49 +0800 [thread overview]
Message-ID: <tencent_3A9F8B9B42B78063768F15C6908EA295E806@qq.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 417 bytes --]
shr.el has already a blacklist feature via `shr-blocked-images'
variable. However in the setting of using shr as an email pager to
display HTML contents, it is much more useful to have a "whitelist"
feature.
Summary of changes:
Added variable `shr-safe-images', nil means all images are
allowed. This can be overriden by setting existed `shr-blocked-images'.
Added subst function `shr-image-is-blocked'.
--
LDB
[-- Attachment #2: shr_whitelist.patch --]
[-- Type: text/plain, Size: 2358 bytes --]
--- shr.el.old 2021-12-18 16:04:43.000000000 +0800
+++ shr.el 2021-12-18 16:18:30.000000000 +0800
@@ -56,8 +56,16 @@
:version "24.1"
:type 'float)
+(defcustom shr-safe-images nil
+ "Only images that have URLs matching this regexp will be displayed.
+The nil value means all URLs are allowed. This can be overrided
+by `shr-blocked-images'."
+ :version "29.1"
+ :type '(choice (const nil) regexp))
+
(defcustom shr-blocked-images nil
- "Images that have URLs matching this regexp will be blocked."
+ "Images that have URLs matching this regexp will be blocked.
+This take effect in prior to `shr-safe-images'."
:version "24.1"
:type '(choice (const nil) regexp))
@@ -483,6 +491,12 @@
(shr-insert sub)
(shr-descend sub))))
+(defsubst shr-image-is-blocked (url)
+ (or (and shr-blocked-images
+ (string-match shr-blocked-images url))
+ (and shr-safe-images
+ (not (string-match shr-safe-images url)))))
+
(defun shr-indirect-call (tag-name dom &rest args)
(let ((function (intern (concat "shr-tag-" (symbol-name tag-name)) obarray))
;; Allow other packages to override (or provide) rendering
@@ -1186,7 +1200,7 @@
;; SVG images may contain references to further images that we may
;; want to block. So special-case these by parsing the XML data
;; and remove anything that looks like a blocked bit.
- (when (and shr-blocked-images
+ (when (and (or shr-safe-images shr-blocked-images)
(eq content-type 'image/svg+xml))
(setq data
;; Note that libxml2 doesn't parse everything perfectly,
@@ -1380,8 +1394,7 @@
((or (not (eq (dom-tag elem) 'image))
;; Filter out blocked elements inside the SVG image.
(not (setq url (dom-attr elem ':xlink:href)))
- (not shr-blocked-images)
- (not (string-match shr-blocked-images url)))
+ (not (shr-image-is-blocked url)))
(insert " ")
(shr-dom-print elem)))))
(insert (format "</%s>" (dom-tag dom))))
@@ -1657,8 +1670,7 @@
(funcall shr-put-image-function image alt
(list :width width :height height)))))
((or shr-inhibit-images
- (and shr-blocked-images
- (string-match shr-blocked-images url)))
+ (shr-image-is-blocked url))
(setq shr-start (point))
(shr-insert alt))
((and (not shr-ignore-cache)
next reply other threads:[~2021-12-18 8:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-18 8:22 LdBeth [this message]
2021-12-19 11:26 ` bug#52594: [PATCH] Add image whiltelist to shr.el Lars Ingebrigtsen
2021-12-20 6:18 ` LdBeth
2021-12-20 10:18 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_3A9F8B9B42B78063768F15C6908EA295E806@qq.com \
--to=andpuke@foxmail.com \
--cc=52594@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.