Commit eb5284b1d6740555cfb75c17f005db95cc61cca8

Thomas de Grivel 2015-06-27T19:43:41

Fix URI template expansion for multiple variables in prefixed op.

diff --git a/uri-template.lisp b/uri-template.lisp
index e09c0ce..5db835c 100644
--- a/uri-template.lisp
+++ b/uri-template.lisp
@@ -312,17 +312,21 @@ URI-TEMPLATE."
   (let (vars)
     (values
      (do-uri-template template
-       :string (lambda (x) `(write-string ,x ,stream-var))
-       :op (lambda (op &rest v) `(let ((*op* ,op)
-				       (*separator* ,*separator*))
-				   ,@(when-let ((pre (op-prefix op)))
-				       `((write-char ,pre ,stream-var)))
-				   (expand-list (list ,@v)
-						,*separator* stream)))
+       :string (lambda (x) `((write-string ,x ,stream-var)))
+       :parts #'append
+       :op (lambda (op &rest vs)
+             (mapcar (lambda (v)
+                       `(when ,(car (last v))
+                          ,@(when-let ((pre (op-prefix op)))
+                              `((write-char ,pre ,stream-var)))
+                          (let ((*op* ,op)
+                                (*separator* ,*separator*))
+                            (write-string ,v ,stream-var))))
+                     vs))
        :explode (lambda (v) `(let ((*separator* ,*separator*)) ,v))
        :prefix (lambda (n v) `(prefix ,n ,v))
        :var (lambda (v) (pushnew v vars) `(expand-value ,v)))
-     vars)))
+     (nreverse vars))))
 
 #+nil
 (uri-template-expand-code "/assets{/plop*}")