diff options
Diffstat (limited to 'lisp/url/url-util.el')
-rw-r--r-- | lisp/url/url-util.el | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el index f33a58950fc..0aeb141c017 100644 --- a/lisp/url/url-util.el +++ b/lisp/url/url-util.el @@ -163,7 +163,7 @@ Also replaces the \" character, so that the result may be safely used as (defun url-normalize-url (url) "Return a 'normalized' version of URL. Strips out default port numbers, etc." - (let (type data grok retval) + (let (type data retval) (setq data (url-generic-parse-url url) type (url-type data)) (if (member type '("www" "about" "mailto" "info")) @@ -352,17 +352,31 @@ 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." + ;; To go faster and avoid a lot of consing, we could do: + ;; + ;; (defconst url-hexify-table + ;; (let ((map (make-vector 256 nil))) + ;; (dotimes (byte 256) (aset map byte + ;; (if (memq byte url-unreserved-chars) + ;; (char-to-string byte) + ;; (format "%%%02x" byte)))) + ;; map)) + ;; + ;; (mapconcat (curry 'aref url-hexify-table) ...) + (mapconcat (lambda (byte) + (if (memq byte url-unreserved-chars) + (char-to-string byte) + (format "%%%02x" byte))) + (if (multibyte-string-p string) + (encode-coding-string string 'utf-8) + string) + "")) ;;;###autoload (defun url-file-extension (fname &optional x) @@ -389,7 +403,6 @@ then return the basename of the file with the extension stripped off." WIDTH defaults to the current frame width." (let* ((fr-width (or width (frame-width))) (str-width (length url)) - (tail (file-name-nondirectory url)) (fname nil) (modified 0) (urlobj nil)) @@ -397,8 +410,7 @@ WIDTH defaults to the current frame width." (if (and (>= str-width fr-width) (string-match "?" url)) (setq url (concat (substring url 0 (match-beginning 0)) "?...") - str-width (length url) - tail (file-name-nondirectory url))) + str-width (length url))) (if (< str-width fr-width) nil ; Hey, we are done! (setq urlobj (url-generic-parse-url url) |