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.
This commit is contained in:
Stefan Kangas 2023-02-17 22:50:13 +01:00
parent b37cb465fe
commit 2c7e87c73a
2 changed files with 21 additions and 5 deletions

View file

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

View file

@ -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"))