Commit 3ee7780ec8a3226e3b6e99dbc0225989ac35091b

Greg Pfeil 2011-03-18T22:50:47

Cleaned up URL parameter handling.

diff --git a/gravatar.lisp b/gravatar.lisp
index 1224cce..63c423b 100644
--- a/gravatar.lisp
+++ b/gravatar.lisp
@@ -15,23 +15,24 @@
    :identicon, :monsterid, :wavatar, or :retro. RATING may be one of :g, :pg,
    :r, or :x."
   (let ((parameters ()))
-    (when size (push (format nil "s=~d" size) parameters))
+    (when size (push `("s" . ,(format nil "~d" size)) parameters))
     (typecase default
-      (keyword (push (format nil "d=~a" (string-downcase default)) parameters))
-      (string (push (format nil "d=~a" default) parameters)))
-    (when force-default-p (push "f=y" parameters))
-    (when rating (push (format nil "r=~a" (string-downcase rating)) parameters))
-    (puri:merge-uris (format nil "avatar/~a~@[?~{~a~^&~}~]"
-                             (hash email) parameters)
+      (keyword (push `("d" . ,(string-downcase default)) parameters))
+      (string (push `("d" . ,default) parameters)))
+    (when force-default-p (push '("f" . "y") parameters))
+    (when rating (push `("r" . ,(string-downcase rating)) parameters))
+    (puri:merge-uris (format nil "avatar/~a~@[?~a~]"
+                             (hash email)
+                             (drakma::alist-to-url-encoded-string parameters
+                                                                  :utf-8))
                      +base-uri+)))
 
 (defun generate-profile-url (email type parameters)
-  (puri:merge-uris (format nil "g2-~a.~a~@[?~:{~a=~a~^&~}~]"
+  (puri:merge-uris (format nil "g2-~a.~a~@[?~a~]"
                            (hash email)
                            (string-downcase type)
-                           (mapcar (lambda (parameter)
-                                     (list (car parameter) (cdr parameter)))
-                                   parameters))
+                           (drakma::alist-to-url-encoded-string parameters
+                                                                :utf-8))
                    +base-uri+))
 
 (defun profile (email &optional js-callback)
@@ -44,4 +45,6 @@
                             `(("callback" . ,js-callback))))))))
 
 (defun qr-code-url (email &optional size)
-  (generate-profile-url email :qr (when size `(("s" . ,size)))))
+  (generate-profile-url email
+                        :qr
+                        (when size `(("s" . ,(format nil "~d" size))))))