From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Felix Dietrich Newsgroups: gmane.emacs.bugs Subject: bug#65224: =?UTF-8?Q?mailcap-viewer-passes-test=E2=80=99s?= caching interferes with precomputed tests Date: Fri, 11 Aug 2023 12:48:49 +0200 Message-ID: <877cq1rh0u.fsf@sperrhaken.name> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21490"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: 65224@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Aug 11 12:50:17 2023 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 1qUPii-0005MD-Fy for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 11 Aug 2023 12:50:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUPiW-00037s-Cs; Fri, 11 Aug 2023 06:50:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qUPiU-00037X-Ea for bug-gnu-emacs@gnu.org; Fri, 11 Aug 2023 06:50:02 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUPiU-0003K1-6Q for bug-gnu-emacs@gnu.org; Fri, 11 Aug 2023 06:50:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qUPiU-0000Wr-2H for bug-gnu-emacs@gnu.org; Fri, 11 Aug 2023 06:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Felix Dietrich Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 11 Aug 2023 10:50:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 65224 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs Original-Received: via spool by submit@debbugs.gnu.org id=B.16917509681981 (code B ref -1); Fri, 11 Aug 2023 10:50:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Aug 2023 10:49:28 +0000 Original-Received: from localhost ([127.0.0.1]:45018 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUPhv-0000Vt-V0 for submit@debbugs.gnu.org; Fri, 11 Aug 2023 06:49:28 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:46644) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUPhu-0000Vg-4L for submit@debbugs.gnu.org; Fri, 11 Aug 2023 06:49:27 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qUPhm-0002na-FU for bug-gnu-emacs@gnu.org; Fri, 11 Aug 2023 06:49:18 -0400 Original-Received: from mout.kundenserver.de ([212.227.126.134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qUPhk-0003GI-E6 for bug-gnu-emacs@gnu.org; Fri, 11 Aug 2023 06:49:18 -0400 Original-Received: from localhost ([77.191.1.9]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MofLl-1q2Fsm06m1-00p7Uv for ; Fri, 11 Aug 2023 12:49:13 +0200 X-Provags-ID: V03:K1:WN9/Lq3NGGvCayJ64JDROes+sqod6rM9d4U541RJipN72rZ5m3d 1Gq8xuSI5LoJW9G+OWa+6BDEH92KRitAliawp7HgAzzsZaAfXaxutKm9DJqV+VK2XJVYtdd lUsnKODu5ckRBKupjQ/RKDZgxK7BJI251x6nyR/fJ++gFh82FNKJRCKNwGs/F9/H5eav1Dx DVUpJ5h5chjn/642mocXg== UI-OutboundReport: notjunk:1;M01:P0:ErsviZDKWCI=;AKfVDQml0LS7fPCJDHwnCIBcoaJ sOybWd+7i4MFf23F750lmFu4vLT0O33ioChgbNL2+mPYbCUxsxNa5WcR5683nGjgKubfUZVf+ i2eh1+7Ap36MThuV/XO2H5g4Ug5Maltc4HDS5EgkbwnqG2flaOoS1jWKpT+q8QtIxIsD+3J3h P/xzM1fCegJC7uTJdyK4ChEicGg/ripiPtB5hvxiYMBKlXKeclxht2mILvKqOuq9VIvU8Cmfs MJ6+hcAI5D+FlCf8C2+N7jEgjUP0jUBo/ji5vCAzoTWDpIKdlQszorww54SrHExZ3OEU5XjpV aI+PP+XBVUmLNWcRr8s+690LCncLLms+SUDmopZGPmghy6jFkLNyZ+DNcrOU3LcY0tCeQOjYJ PTGVtK7Bh0UjqdpfYFKYu+0tK6R9a9EJSBHvHr5vPdLb/Hd8AfKyZmvEz+TWlic+DP03yi9FW MrRo2qhvKzIo0z03zH879z1uAataW1am12RHizQiT60aDkjpYj6EaQFpf/s9MsLX3jOuY/iye lbT7+YJqgXlmTV7CDSTT1gButbUMzGyshOscEfComTY9XMB7AgjZrIfmstqnM/wWRGrW0uVr/ tMb+8S0CBq2M02TCacJGENSpM7yEhBfP8kca/QKOd9hWk1ZMHmYsS0bVaokld6JhXDA67JjKf gEuhb1kVjr39s3pCHzyzvJNEcV4W50c2rPHxQFGnKXegwMdjT+0z18pelnqfrxPVMjWi7izuv mdpRcl6F81Jk5tWtBgM93988eaDId9/b2wgCmHnfgXLlIMI2jG2m9HK/2fwrht/ow5PPnFyo Received-SPF: pass client-ip=212.227.126.134; envelope-from=felix.dietrich@sperrhaken.name; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:267204 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable When called with a VIEWER-INFO that does not contain a test, =E2=80=98mailcap-viewer-passes-test=E2=80=99 erroneously returns nil if it = had previously been called with a VIEWER-INFO whose test was explicitly set to nil. As a consequence =E2=80=98mailcap-mime-info=E2=80=99 (used e.g. by =E2=80=98gnus-mime-view-part-externally=E2=80=99) may return the wrong view= er. The reason is that =E2=80=98mailcap-viewer-passes-test=E2=80=99 adds tests = that are explicitly nil (i.e. (test . nil)) to the cache as (nil nil) (first the test, second the result) and checks for the non-existence of a test only after it has tried to find the test result in the cache. The test variable for a VIEWER-INFO without a test is nil, and, therefore, the assoc lookup for nil done on the cache yields (nil nil) and, hence, nil (the cadr) as the test result. Moving the check for the non-existence of a test before the cache lookup fixes the issue; this is what the attached patch does. In the log message the bug number (Bug#) needs to be filled in. --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=0001-Make-mailcap-viewer-passes-test-return-t-for-viewers.patch Content-Transfer-Encoding: quoted-printable Content-Description: Patch with fix and test >From 811ef5f697e165c58c54b3839672c920336da947 Mon Sep 17 00:00:00 2001 From: Felix Dietrich Date: Sun, 6 Aug 2023 06:01:24 +0200 Subject: [PATCH] =3D?UTF-8?q?Make=3D20=3DE2=3D80=3D98mailcap-viewer-passes-= test?=3D =3D?UTF-8?q?=3DE2=3D80=3D99=3D20return=3D20t=3D20for=3D20viewers=3D20witho= ut=3D20tests?=3D MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit * lisp/net/mailcap.el (mailcap-viewer-passes-test): Make =E2=80=98mailcap-viewer-passes-test=E2=80=99 follow its docstring and = return t for viewers without a test. (Bug#) * test/lisp/net/mailcap-tests.el (mailcap-viewer-passes-test-w/o-test-returns-t): New test. --- lisp/net/mailcap.el | 2 +- test/lisp/net/mailcap-tests.el | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index 4d01737e3e6..81cc51f1bf0 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -689,9 +689,9 @@ to supply to the test." status cache result) (cond ((not (or (stringp viewer) (fboundp viewer))) nil) ; Non-existent Lisp function + ((null test-info) t) ; No test clause ((setq cache (assoc test mailcap-viewer-test-cache)) (cadr cache)) - ((not test-info) t) ; No test clause (t (setq result diff --git a/test/lisp/net/mailcap-tests.el b/test/lisp/net/mailcap-tests.el index e47ead98f42..fa72d1bd285 100644 --- a/test/lisp/net/mailcap-tests.el +++ b/test/lisp/net/mailcap-tests.el @@ -537,5 +537,30 @@ help to verify the correct addition and merging of an = entry." ("minor" . ((viewer . "viewer") (edit . "edit"))))))))) =20 + + +(ert-deftest mailcap-viewer-passes-test-w/o-test-returns-t () + "A VIEWER-INFO without a test should return t with a valid viewer." + + (should (equal t + (let ((mailcap-viewer-test-cache) + (viewer-info + (list (cons 'viewer "viewer-w/o-test")))) + (mailcap-viewer-passes-test viewer-info nil)))) + + (should (equal '(t t nil t) + (let ((mailcap-viewer-test-cache) + (viewer-infos + (list + (list (cons 'viewer "viewer-w/o-test")) + (list (cons 'viewer "viewer-w/o-test")) + (list (cons 'viewer "viewer-w/nil-test") + (cons 'test nil)) + (list (cons 'viewer "viewer-w/o-test")) + ))) + (mapcar (lambda (vi) + (mailcap-viewer-passes-test vi nil)) + viewer-infos))))) + =20 ;;; mailcap-tests.el ends here --=20 2.40.1 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable The following example calls =E2=80=98mailcap-viewer-passes-test=E2=80=99 fo= ur times. For the first, second and third call the VIEWER-INFO does not contain a test; for the third the test is nil. The results show that the first and second call correctly return t; the third with (test . nil) correctly returns nil and adds (nil nil) to the cache; the fourth, then, incorrectly returns nil. #+HEADER: :results table #+begin_src emacs-lisp (let (mailcap-viewer-test-cache (viewer-infos (list (list (cons 'viewer "viewer-w/o-test")) (list (cons 'viewer "viewer-w/o-test")) (list (cons 'viewer "viewer-w/-test-nil") (cons 'test nil)) (list (cons 'viewer "viewer-w/o-test"))))) (cl-list* (list "Index" "Viewer" "Passes Test" "Cache after Call") 'hline (cl-loop for i =3D 1 then (1+ i) for vi in viewer-infos collect (list (format "%i." i) (alist-get 'viewer vi) (mailcap-viewer-passes-test vi ni= l) mailcap-viewer-test-cache)))) #+end_src #+RESULTS: | Index | Viewer | Passes Test | Cache after Call | |-------+--------------------+-------------+------------------| | 1. | viewer-w/o-test | t | nil | | 2. | viewer-w/o-test | t | nil | | 3. | viewer-w/-test-nil | nil | ((nil nil)) | | 4. | viewer-w/o-test | nil | ((nil nil)) | --=20 Felix Dietrich --=-=-=--