[bknr-cvs] hans changed trunk/thirdparty/hunchentoot/util.lisp
BKNR Commits
bknr at bknr.net
Thu Sep 4 13:09:36 UTC 2008
Revision: 3790
Author: hans
URL: http://bknr.net/trac/changeset/3790
Special case for zero-length string.
U trunk/thirdparty/hunchentoot/util.lisp
Modified: trunk/thirdparty/hunchentoot/util.lisp
===================================================================
--- trunk/thirdparty/hunchentoot/util.lisp 2008-09-04 12:18:43 UTC (rev 3789)
+++ trunk/thirdparty/hunchentoot/util.lisp 2008-09-04 13:09:36 UTC (rev 3790)
@@ -243,43 +243,45 @@
(defun url-decode (string &optional (external-format *hunchentoot-default-external-format*))
"Decodes a URL-encoded STRING which is assumed to be encoded using
the external format EXTERNAL-FORMAT."
- (loop
- with vector = (make-array (length string) :element-type 'octet :fill-pointer 0)
- with i = 0
- with unicode
- for char = (aref string i)
- do (labels ((decode-hex (length)
- (prog1
- (parse-integer string :start i :end (+ i length) :radix 16)
- (incf i length)))
- (push-integer (integer)
- (vector-push integer vector))
- (peek ()
- (aref string i))
- (advance ()
- (setf char (peek))
- (incf i)))
- (cond
- ((char= #\% char)
- (advance)
- (cond
- ((char= #\u (peek))
- (unless unicode
- (setf unicode t)
- (upgrade-vector vector '(integer 0 65535)))
- (advance)
- (push-integer (decode-hex 4)))
- (t
- (push-integer (decode-hex 2)))))
- (t
- (push-integer (char-code (case char
- ((#\+) #\Space)
- (otherwise char))))
- (advance))))
- while (< i (length string))
- finally (return (if unicode
- (upgrade-vector vector 'character :converter #'code-char)
- (octets-to-string vector :external-format external-format)))))
+ (if (zerop (length string))
+ ""
+ (loop
+ with vector = (make-array (length string) :element-type 'octet :fill-pointer 0)
+ with i = 0
+ with unicode
+ for char = (aref string i)
+ do (labels ((decode-hex (length)
+ (prog1
+ (parse-integer string :start i :end (+ i length) :radix 16)
+ (incf i length)))
+ (push-integer (integer)
+ (vector-push integer vector))
+ (peek ()
+ (aref string i))
+ (advance ()
+ (setf char (peek))
+ (incf i)))
+ (cond
+ ((char= #\% char)
+ (advance)
+ (cond
+ ((char= #\u (peek))
+ (unless unicode
+ (setf unicode t)
+ (upgrade-vector vector '(integer 0 65535)))
+ (advance)
+ (push-integer (decode-hex 4)))
+ (t
+ (push-integer (decode-hex 2)))))
+ (t
+ (push-integer (char-code (case char
+ ((#\+) #\Space)
+ (otherwise char))))
+ (advance))))
+ while (< i (length string))
+ finally (return (if unicode
+ (upgrade-vector vector 'character :converter #'code-char)
+ (octets-to-string vector :external-format external-format))))))
(defun form-url-encoded-list-to-alist (form-url-encoded-list
&optional (external-format *hunchentoot-default-external-format*))
More information about the Bknr-cvs
mailing list