From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: LdBeth Newsgroups: gmane.emacs.bugs Subject: bug#52594: [PATCH] Add image whiltelist to shr.el Date: Sat, 18 Dec 2021 16:22:49 +0800 Message-ID: Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Sat_Dec_18_16:22:49_2021-1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19895"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?Q?Goj=C5=8D?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.2 (x86_64-apple-darwin18.7.0) MULE/6.0 (HANACHIRUSATO) To: 52594@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 18 09:25:15 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1myV1k-0004uQ-Bs for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 18 Dec 2021 09:25:13 +0100 Original-Received: from localhost ([::1]:41314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1myV1i-0003aM-Vo for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 18 Dec 2021 03:25:11 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:37918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1myV1a-0003aD-IB for bug-gnu-emacs@gnu.org; Sat, 18 Dec 2021 03:25:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57919) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1myV1a-0004zl-A9 for bug-gnu-emacs@gnu.org; Sat, 18 Dec 2021 03:25:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1myV1a-0001WA-2i for bug-gnu-emacs@gnu.org; Sat, 18 Dec 2021 03:25:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: LdBeth Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 18 Dec 2021 08:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 52594 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16398158655786 (code B ref -1); Sat, 18 Dec 2021 08:25:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 Dec 2021 08:24:25 +0000 Original-Received: from localhost ([127.0.0.1]:41232 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1myV0y-0001VG-Vj for submit@debbugs.gnu.org; Sat, 18 Dec 2021 03:24:25 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:42858) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1myV0v-0001V7-Ho for submit@debbugs.gnu.org; Sat, 18 Dec 2021 03:24:23 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:37852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1myV0u-0003Uk-Cj for bug-gnu-emacs@gnu.org; Sat, 18 Dec 2021 03:24:21 -0500 Original-Received: from out162-62-57-210.mail.qq.com ([162.62.57.210]:36983) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1myV0m-0004vQ-4z for bug-gnu-emacs@gnu.org; Sat, 18 Dec 2021 03:24:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1639815843; bh=ot2IgCtYx5QgPGwWauSyyt4nR4lK2EoKQ0aH4N/o5vE=; h=Date:From:To:Subject; b=o0ZJzZpDCKnFuQQxE42xCjmIh2bOzRhYw5bN4BLOOvvIHmTRmxTSCjKUArRSM48Hn Qqs8VOSatUa7tjY8fuFFuKHcwPqfaLhvN72ZxzyPz2Oye5tc+K+cVv8dlKBk4NUdZn S/G/n6nGhQGrc3zg7Y3cqqnhGdgmR2YUMMHwAui0= Original-Received: from Costume-Party.local ([39.189.56.217]) by newxmesmtplogicsvrszc11.qq.com (NewEsmtp) with SMTP id 5B215076; Sat, 18 Dec 2021 16:22:50 +0800 X-QQ-mid: xmsmtpt1639815770tlqp748yv X-QQ-XMAILINFO: ND42uzdxTIzrffLWC+r7eVRAg4dXwZZYan8ZvLsE75eApD25cdoZmNWChkgoRT E2TnW7bLSJMF76Y2CaV99ywWoSMisFkR/az77fnH5YZYrf66dhACAiF+1OGvf9faELm+XUYGozi/ UYe8DmmAS4WqrR/6W02i0Y2RZ6OKopjVuPBCEVzlplDv05wCvlRghmcM4F3RbZKljZ3/gyROy/ks z4Yha0NTcnfjgEFzm77m0mYHooTrtyzMtEfShUTufw/gS8Q+g+ifOeeek8aoBmYWlpCPSdZ4OfzS E/hetv0HR22hN6ILBKsURJF6vweQBX5FpXYUBFyqH+9WXx9aywfq7OEvPvhAkAzcSd9SZq7x9tGD cG4Y3HY8MExkVV+gNCafaNAm2dPlE2JgKXaVNWCjWgTGOr+EU1leBqnmoT2xr6ezgZDAVeBesoq/ PELeJXDSHHgQoRTEz2slHM747/7EmEnCyWp5U+IDptTh7V4EJ79kU1H/FTncy8xooN6KtqN1qkQP 8hwIaVO02OnyRUzTc43UdLkfTbXDJjREI3/u1f8P3KPnSztK21nm5d3R8uIesl/cj31HZYav8ziY CcBOKzvXFZgxuP4P16t6q6BP0NwAHNq1qmImlDnH/UtuQulRR7ZU8yFrPwyHDGBMXLybZrSOfrUs 7WiNA/SmiMByEsUsLFAAip/LIRlywlnNjaj/5kIi0/tPUaJrfRl3uNWZr7wV4zAoLZV/lfC2AJWj HxOws2nks2jyadNi2lwE9eFYQVlU/CCcV05TZg0ofA3/m8vsfGAJ41M958V/w0gaSJE1p9hLQErX fXXFM8f/PyNeEroSy8on9tJugXxCo9LzApHIe64h Original-Received: by Costume-Party.local (Postfix, from userid 501) id 16400203CFE695; Sat, 18 Dec 2021 16:22:49 +0800 (CST) X-OQ-MSGID: X-Face: $7|yD%Lji?.p'#Ya#/C7iZ!+-!NJjcGAgDR]\PSw$5:"t{7P+VEqKM:>~f#x)H2jckGF($uh>W~_Qc/,O|&mg(HAmk,P?*}P]1w1Y6R_Eu/njc; o>(_\1T$MB3M3oPTM:cv83P$`O)F{ID*m}x3S#}+?w!"kF@h<68U0'ti>$=J2.&mQw~Z^#:2FP(bF)(Y:}1r~W~@(5IR!|_C*Fy*gERgk6F!; m"e"hC`I; TMK1O_l&i+Ja)s9d2; {xTNv&gp/>w>#aSg)P:%$oVI*V[LFED=+xNrHX-!#}\U] Received-SPF: pass client-ip=162.62.57.210; envelope-from=andpuke@foxmail.com; helo=out162-62-57-210.mail.qq.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HELO_DYNAMIC_IPADDR=1.951, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RDNS_DYNAMIC=0.982, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, TO_NO_BRKTS_DYNIP=0.245 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:222601 Archived-At: --Multipart_Sat_Dec_18_16:22:49_2021-1 Content-Type: text/plain; charset=US-ASCII 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 --Multipart_Sat_Dec_18_16:22:49_2021-1 Content-Type: text/plain; type=patch; name="shr_whitelist.patch"; charset=US-ASCII Content-Disposition: attachment; filename="shr_whitelist.patch" Content-Transfer-Encoding: 7bit --- 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 "" (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) --Multipart_Sat_Dec_18_16:22:49_2021-1--