From: Lars Ingebrigtsen Date: Fri, 31 Jul 2020 02:19:03 +0000 (+0200) Subject: Make gravatar-build-url respect dynamically bound variables again X-Git-Tag: emacs-28.0.90~6888 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=50a12de877b752a4830b55beb196a7c3c1b7f715;p=emacs.git Make gravatar-build-url respect dynamically bound variables again * lisp/image/gravatar.el (gravatar-build-url): Compute query-string first, so that dynamically bound values of `gravatar-rating' (etc.) are respected, instead of computing it when the callback happens. --- diff --git a/lisp/image/gravatar.el b/lisp/image/gravatar.el index ff612d2e9f3..d1091e57cb5 100644 --- a/lisp/image/gravatar.el +++ b/lisp/image/gravatar.el @@ -188,14 +188,15 @@ to track whether you're reading a specific mail." (defun gravatar-build-url (mail-address callback) "Find the URL of a gravatar for MAIL-ADDRESS and call CALLBACK with it." ;; https://gravatar.com/site/implement/images/ - (funcall (alist-get gravatar-service gravatar-service-alist) - mail-address - (lambda (url) - (funcall callback - (format "%s/%s?%s" - url - (gravatar-hash mail-address) - (gravatar--query-string)))))) + (let ((query-string (gravatar--query-string))) + (funcall (alist-get gravatar-service gravatar-service-alist) + mail-address + (lambda (url) + (funcall callback + (format "%s/%s?%s" + url + (gravatar-hash mail-address) + query-string)))))) (defun gravatar-get-data () "Return body of current URL buffer, or nil on failure." diff --git a/test/lisp/image/gravatar-tests.el b/test/lisp/image/gravatar-tests.el index e66b5c6803d..43c3024721e 100644 --- a/test/lisp/image/gravatar-tests.el +++ b/test/lisp/image/gravatar-tests.el @@ -65,8 +65,13 @@ "Test `gravatar-build-url'." (let ((gravatar-default-image nil) (gravatar-force-default nil) - (gravatar-size nil)) - (should (equal (gravatar-build-url "foo") "\ + (gravatar-size nil) + (gravatar-service 'gravatar) + url) + (gravatar-build-url "foo" (lambda (u) (setq url u))) + (while (not url) + (sleep-for 0.01)) + (should (equal url "\ https://www.gravatar.com/avatar/acbd18db4cc2f85cedef654fccc4a4d8?r=g")))) ;;; gravatar-tests.el ends here