unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#52594: [PATCH] Add image whiltelist to shr.el
@ 2021-12-18  8:22 LdBeth
  2021-12-19 11:26 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: LdBeth @ 2021-12-18  8:22 UTC (permalink / raw)
  To: 52594

[-- 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)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#52594: [PATCH] Add image whiltelist to shr.el
  2021-12-18  8:22 bug#52594: [PATCH] Add image whiltelist to shr.el LdBeth
@ 2021-12-19 11:26 ` Lars Ingebrigtsen
  2021-12-20  6:18   ` LdBeth
  0 siblings, 1 reply; 4+ messages in thread
From: Lars Ingebrigtsen @ 2021-12-19 11:26 UTC (permalink / raw)
  To: LdBeth; +Cc: 52594

LdBeth <andpuke@foxmail.com> writes:

> 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.

Seems useful, so I added this to Emacs 29 (but changed the name of the
user option and functions).

This change was small enough to apply without assigning copyright to the
FSF, but for future patches you want to submit, it might make sense to
get the paperwork started now, so that subsequent patches can be applied
speedily. Would you be willing to sign such paperwork?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#52594: [PATCH] Add image whiltelist to shr.el
  2021-12-19 11:26 ` Lars Ingebrigtsen
@ 2021-12-20  6:18   ` LdBeth
  2021-12-20 10:18     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: LdBeth @ 2021-12-20  6:18 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: LdBeth, 52594

On Sun, 19 Dec 2021 19:26:53 +0800,

Sure, I am willing to sign the copyright paperwork for future
contributions to Emacs.

-- 
LDB

Lars Ingebrigtsen wrote:
> 
> LdBeth <andpuke@foxmail.com> writes:
> 
> > 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.
> 
> Seems useful, so I added this to Emacs 29 (but changed the name of the
> user option and functions).
> 
> This change was small enough to apply without assigning copyright to the
> FSF, but for future patches you want to submit, it might make sense to
> get the paperwork started now, so that subsequent patches can be applied
> speedily. Would you be willing to sign such paperwork?
> 
> -- 
> (domestic pets only, the antidote for overdose, milk.)
>    bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#52594: [PATCH] Add image whiltelist to shr.el
  2021-12-20  6:18   ` LdBeth
@ 2021-12-20 10:18     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2021-12-20 10:18 UTC (permalink / raw)
  To: LdBeth; +Cc: 52594

LdBeth <andpuke@foxmail.com> writes:

> Sure, I am willing to sign the copyright paperwork for future
> contributions to Emacs.

Great; here's the form to get started:

Please email the following information to assign@gnu.org, and we
will send you the assignment form for your past and future changes.

Please use your full legal name (in ASCII characters) as the subject
line of the message.
----------------------------------------------------------------------
REQUEST: SEND FORM FOR PAST AND FUTURE CHANGES

[What is the name of the program or package you're contributing to?]
Emacs

[Did you copy any files or text written by someone else in these changes?
Even if that material is free software, we need to know about it.]

[Do you have an employer who might have a basis to claim to own
your changes?  Do you attend a school which might make such a claim?]

[For the copyright registration, what country are you a citizen of?]

[What year were you born?]

[Please write your email address here.]

[Please write your postal address here.]

[Which files have you changed so far, and which new files have you written
so far?]





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-20 10:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-18  8:22 bug#52594: [PATCH] Add image whiltelist to shr.el LdBeth
2021-12-19 11:26 ` Lars Ingebrigtsen
2021-12-20  6:18   ` LdBeth
2021-12-20 10:18     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).