On 21 July 2010 13:28, Herbert Snorrason <metha...@gmail.com> wrote:
> [...] Drakma doesn't provide a URL-ENCODE function [...]
And after thinking about it, turns out it _does_, just doesn't expose
it. The thinking is, I presume, that all URL-encoded data should pass
through another interface that handles the cleaning?

In any case, the attached patch updates url-encode to RFC3986 (or at
least only passes that standard's "unreserved characters" through) and
exposes it.

With greetings,
  Herbert Snorrason
diff -ur ./doc/index.html ../url-encode/doc/index.html
--- ./doc/index.html	2010-07-10 10:02:53.000000000 +0000
+++ ../url-encode/doc/index.html	2010-07-21 14:52:48.000000000 +0000
@@ -109,6 +109,10 @@
           <li><a href="#cookie-error-cookie"><code>cookie-error-cookie</code></a>
           <li><a href="#cookie-date-parse-error"><code>cookie-date-parse-error</code></a>
         </ol>
+      <li><a href="#misc">Miscellaneous</a>
+        <ol>
+          <li><a href="#url-encode"><code>url-encode</code></a>
+        </ol>
     </ol>
   <li><a href="#prob">Potential problems</a>
   <li><a href="#ack">Acknowledgements</a>
@@ -1558,6 +1562,21 @@
 
 <!-- End of entry for GET-CONTENT-TYPE -->
 
+<h4><a name="misc" class=none>Miscellaneous</a></h4>
+
+Utility function(s) that don't exactly fit anywhere else.
+
+<!-- Entry for URL-ENCODE -->
+
+<p><br>[Function]<br><a class=none name='url-encode'><b>url-encode</b> <i>string <tt>&amp;optional</tt> external-format</i> =&gt; <i>result</i></a>
+<blockquote><br>
+
+URL-encodes a string using the external format <code><i>external-format</i></code>.
+
+</blockquote>
+
+<!-- End of entry for URL-ENCODE -->
+
 <h4><a name="conditions" class=none>Conditions</a></h4>
 
 This section lists all the condition types that are defined by Drakma.
diff -ur ./packages.lisp ../url-encode/packages.lisp
--- ./packages.lisp	2010-07-10 10:02:53.000000000 +0000
+++ ../url-encode/packages.lisp	2010-07-21 13:58:48.000000000 +0000
@@ -68,4 +68,5 @@
            :parse-cookie-date
            :read-tokens-and-parameters
            :split-tokens
-           :syntax-error))
+           :syntax-error
+           :url-encode))
diff -ur ./util.lisp ../url-encode/util.lisp
--- ./util.lisp	2010-07-10 10:02:53.000000000 +0000
+++ ../url-encode/util.lisp	2010-07-21 13:55:41.000000000 +0000
@@ -93,9 +93,8 @@
     (or (null mismatch)
         (= mismatch (length prefix)))))
 
-(defun url-encode (string external-format)
-  "Returns a URL-encoded version of the string STRING using the
-LispWorks external format EXTERNAL-FORMAT."
+(defun url-encode (string &optional (external-format *drakma-default-external-format*))
+  "URL-encodes a string using the external format EXTERNAL-FORMAT."
   (with-output-to-string (out)
     (loop for octet across (string-to-octets (or string "")
                                              :external-format external-format)
@@ -103,10 +102,8 @@
           do (cond ((or (char<= #\0 char #\9)
                         (char<= #\a char #\z)
                         (char<= #\A char #\Z)
-                        (find char "$-_.!*'()," :test #'char=))
+                        (find char "-_.~" :test #'char=))
                      (write-char char out))
-                   ((char= char #\Space)
-                     (write-char #\+ out))
                    (t (format out "%~2,'0x" (char-code char)))))))
 
 (defun alist-to-url-encoded-string (alist external-format)
_______________________________________________
drakma-devel mailing list
drakma-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/drakma-devel

Reply via email to