From 2c7e87c73a90effab66fa7c783855199880315d3 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Fri, 17 Feb 2023 22:50:13 +0100 Subject: [PATCH] Use more recent public_suffix_list.dat where possible * lisp/url/url-domsuf.el (url-domsuf--public-suffix-file): New function to look for a more recent version of public_suffix_list.dat on the system than the one that is shipped with Emacs. (url-domsuf-parse-file): Use above new function. * test/lisp/url/url-domsuf-tests.el (url-domsuf--public-suffix-file): New test. --- lisp/url/url-domsuf.el | 22 +++++++++++++++++----- test/lisp/url/url-domsuf-tests.el | 4 ++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lisp/url/url-domsuf.el b/lisp/url/url-domsuf.el index 74d46f1c037..671885e418f 100644 --- a/lisp/url/url-domsuf.el +++ b/lisp/url/url-domsuf.el @@ -30,14 +30,26 @@ (defvar url-domsuf-domains nil) +(defun url-domsuf--public-suffix-file () + "Look for and return a file name for a recent \"public_suffix_list.dat\". +Emacs ships with a copy of this file, but some systems might have +a newer version available. Look for it in some standard +locations, and if a newer file was found, then return that." + (car (sort + (seq-filter + #'file-readable-p + (list (expand-file-name "publicsuffix.txt.gz" data-directory) + (expand-file-name "publicsuffix.txt" data-directory) + ;; Debian and Fedora + "/usr/share/publicsuffix/public_suffix_list.dat" + ;; FreeBSD port + "/usr/local/share/public_suffix_list/public_suffix_list.dat")) + #'file-newer-than-file-p))) + (defun url-domsuf-parse-file () (with-temp-buffer (with-auto-compression-mode - (insert-file-contents - (let* ((suffixfile (expand-file-name "publicsuffix.txt" data-directory)) - (compressed-file (concat suffixfile ".gz"))) - (or (and (file-readable-p compressed-file) compressed-file) - suffixfile)))) + (insert-file-contents (url-domsuf--public-suffix-file))) (let ((domains nil) domain exception) (while (not (eobp)) diff --git a/test/lisp/url/url-domsuf-tests.el b/test/lisp/url/url-domsuf-tests.el index 09fd6240065..8dbf65dae44 100644 --- a/test/lisp/url/url-domsuf-tests.el +++ b/test/lisp/url/url-domsuf-tests.el @@ -24,6 +24,10 @@ (require 'url-domsuf) (require 'ert) +(ert-deftest url-domsuf--public-suffix-file () + ;; We should always have a file, since it ships with Emacs. + (should (file-readable-p (url-domsuf--public-suffix-file)))) + (defun url-domsuf-tests--run () (should-not (url-domsuf-cookie-allowed-p "com")) (should (url-domsuf-cookie-allowed-p "foo.bar.bd")) -- 2.39.2