]> git.eshelyaron.com Git - emacs.git/commitdiff
(url-hexify-string): Rewrite.
authorThien-Thi Nguyen <ttn@gnuvola.org>
Sun, 30 Jul 2006 20:21:14 +0000 (20:21 +0000)
committerThien-Thi Nguyen <ttn@gnuvola.org>
Sun, 30 Jul 2006 20:21:14 +0000 (20:21 +0000)
lisp/url/ChangeLog
lisp/url/url-util.el

index 901fac012085d05b967201c45348e8f909973324..e29b4b6b67e12c387b2a680e731f9fd555f9546a 100644 (file)
@@ -1,3 +1,8 @@
+2006-07-30  Thien-Thi Nguyen  <ttn@gnu.org>
+
+       * url-util.el (url-hexify-string): Rewrite.
+       Suggested by David Smith <davidsmith@acm.org>.
+
 2006-07-12  Michael Olson  <mwolson@gnu.org>
 
        * url-irc.el (url-irc-erc): Call erc-handle-irc-url.
index f33a58950fcf701c6274b5bb6343b61352fc6e99..4293b0e301f0c30e512c5ca4d2fd5d6f43c93826 100644 (file)
@@ -352,17 +352,18 @@ forbidden in URL encoding."
 This is taken from RFC 2396.")
 
 ;;;###autoload
-(defun url-hexify-string (str)
-  "Escape characters in a string."
-  (mapconcat
-   (lambda (char)
-     ;; Fixme: use a char table instead.
-     (if (not (memq char url-unreserved-chars))
-        (if (> char 255)
-              (error "Hexifying multibyte character %s" str)
-          (format "%%%02X" char))
-       (char-to-string char)))
-   str ""))
+(defun url-hexify-string (string)
+  "Return a new string that is STRING URI-encoded.
+First, STRING is converted to utf-8, if necessary.  Then, for each
+character in the utf-8 string, those found in `url-unreserved-chars'
+are left as-is, all others are represented as a three-character
+string: \"%\" followed by two lowercase hex digits."
+  (mapconcat (lambda (char)
+               (if (memq char url-unreserved-chars)
+                   (char-to-string char)
+                 (format "%%%02x" char)))
+             (encode-coding-string string 'utf-8 t)
+             ""))
 
 ;;;###autoload
 (defun url-file-extension (fname &optional x)