* lisp/emacs-lisp/lisp-mnt.el (lm-website): Use rx.
* test/lisp/emacs-lisp/lisp-mnt-tests.el
(lm--tests-lm-website): New test.
(defun lm-website (&optional file)
"Return the website in file FILE, or current buffer if FILE is nil."
(let ((page (lm-with-file file
- (lm-header "\\(?:x-\\)?\\(?:url\\|homepage\\)"))))
- (if (and page (string-match "^<.+>$" page))
- (substring page 1 -1)
+ (lm-header (rx (? "x-") (or "url" "homepage"))))))
+ (if (and page (string-match (rx bol "<" (+ nonl) ">" eol) page))
+ (substring page 1 -1)
page)))
(defalias 'lm-homepage 'lm-website) ; for backwards-compatibility
'(("Bob Weiner" . "rsw@gnu.org")
("Mats Lidell" . "matsl@gnu.org")))))
+(ert-deftest lm--tests-lm-website ()
+ (with-temp-buffer
+ (insert ";; URL: https://example.org/foo")
+ (should (string= (lm-website) "https://example.org/foo")))
+ (with-temp-buffer
+ (insert ";; X-URL: <https://example.org/foo>")
+ (should (string= (lm-website) "https://example.org/foo"))))
+
(provide 'lisp-mnt-tests)
;;; lisp-mnt-tests.el ends here