aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--formatters.lisp8
-rw-r--r--json-template.lisp16
2 files changed, 15 insertions, 9 deletions
diff --git a/formatters.lisp b/formatters.lisp
index a16ad93..a183b59 100644
--- a/formatters.lisp
+++ b/formatters.lisp
@@ -23,7 +23,9 @@
(escapee-p (lambda (x) (member x escapees :test #'char=))))
(lambda (string)
(unless (stringp string)
- (setq string (format nil "~A" string)))
+ (typecase string
+ (null (setq string ""))
+ (t (setq string (format nil "~A" string)))))
(with-output-to-string (out)
(loop with position = 0
for escapee-pos = (position-if escapee-p string :start position)
@@ -38,7 +40,9 @@
(defun escape-for-uri (string)
(unless (stringp string)
- (setq string (format nil "~A" string)))
+ (typecase string
+ (null (setq string ""))
+ (t (setq string (format nil "~A" string)))))
(with-output-to-string (out)
(map 'list
(lambda (char)
diff --git a/json-template.lisp b/json-template.lisp
index 0abd91b..5607004 100644
--- a/json-template.lisp
+++ b/json-template.lisp
@@ -177,13 +177,15 @@
(write-string (second thing) stream))
(:variable
(destructuring-bind (variable formatter) (cdr thing)
- (let ((value (lookup-context contexts variable)))
- (format stream "~A"
- (if formatter
- (funcall (cdr (assoc formatter *template-formatters*
- :test #'equal))
- value)
- value)))))
+ (let* ((value (lookup-context contexts variable))
+ (formatted-value (if formatter
+ (funcall (cdr (assoc formatter *template-formatters*
+ :test #'equal))
+ value)
+ value)))
+ (typecase formatted-value
+ (null (values))
+ (t (format stream "~A" formatted-value))))))
(:section
(destructuring-bind (section branch alternative) (cdr thing)
(let ((value (lookup-context contexts section)))