Skip to content

Commit

Permalink
Make URL-ENCODE more closely match the AWS requirements.
Browse files Browse the repository at this point in the history
  • Loading branch information
xach committed Apr 27, 2016
1 parent 0e77b2d commit 1539647
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions utils.lisp
Expand Up @@ -115,13 +115,10 @@
(loop for char across string
do (setf state (funcall state char))))))))

;;; The following two functions were adatpted from Drakma source. The
;;; only change is to escape space as "%20", not #\+ and add the
;;; encode-slash parameter.
;;;
;;; See UriEncode() in
;;; The following two functions were adatpted from Drakma source. It
;;; has been adapted to more closely follow the description of
;;; UriEncode() in
;;; http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html
;;; for the reasoning behind ENCODE-SLASH

(defun url-encode (string &key (encode-slash t))
"Returns a URL-encoded version of the string STRING using the
Expand All @@ -130,11 +127,12 @@ LispWorks external format EXTERNAL-FORMAT."
(with-output-to-string (out)
(loop for octet across (string-octets (or string ""))
for char = (code-char octet)
;;'A'-'Z', 'a'-'z', '0'-'9', '-', '.', '_', and '~'
do (cond ((or (char<= #\0 char #\9)
(char<= #\a char #\z)
(char<= #\A char #\Z)
(and (not encode-slash) (char= char #\/))
(find char "$-_.!*'()," :test #'char=))
(find char "-._~" :test #'char=))
(write-char char out))
((char= char #\Space)
(write-string "%20" out))
Expand Down

0 comments on commit 1539647

Please sign in to comment.