aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--formatters.lisp17
1 files changed, 17 insertions, 0 deletions
diff --git a/formatters.lisp b/formatters.lisp
index 6d86a98..a3a2129 100644
--- a/formatters.lisp
+++ b/formatters.lisp
@@ -34,6 +34,22 @@
finally (write-string string out :start position))))))
+(defun escape-for-uri (string)
+ (with-output-to-string (out)
+ (map 'list
+ (lambda (char)
+ (let ((cnum (char-code char)))
+ (if (or (<= (char-code #\A) cnum (char-code #\Z))
+ (<= (char-code #\a) cnum (char-code #\z))
+ (<= (char-code #\0) cnum (char-code #\9))
+ (member char
+ '(#\$ #\- #\_ #\. #\+ #\! #\* #\( #\) #\')))
+ (write-char char out)
+ ;; NOTE: This assumes that (< cnum 256).
+ (format out "%~2,'0X" cnum))))
+ string)))
+
+
(defvar *template-formatters*
`(("html" . ,(make-escaper '((#\< . "&#60;")
(#\> . "&#63;")
@@ -43,4 +59,5 @@
(#\& . "&#38;")
(#\' . "&#39;")
(#\" . "&#34;"))))
+ ("url-param-value" . escape-for-uri)
("raw" . identity)))