Function: url-encode-url

url-encode-url is an autoloaded and byte-compiled function defined in url-util.el.gz.

Signature

(url-encode-url URL)

Documentation

Return a properly URI-encoded version of URL.

This function also performs URI normalization, e.g. converting the scheme to lowercase if it is uppercase. Apart from normalization, if URL is already URI-encoded, this function should return it unchanged.

Probably introduced at or before Emacs version 24.3.

Aliases

org-link-escape-browser (obsolete since 9.0)

Source Code

;; Defined in /usr/src/emacs/lisp/url/url-util.el.gz
;;;###autoload
(defun url-encode-url (url)
  "Return a properly URI-encoded version of URL.
This function also performs URI normalization, e.g. converting
the scheme to lowercase if it is uppercase.  Apart from
normalization, if URL is already URI-encoded, this function
should return it unchanged."
  (let* ((obj  (url-generic-parse-url url))
	 (user (url-user obj))
	 (pass (url-password obj))
         (path-and-query (url-path-and-query obj))
	 (path  (car path-and-query))
	 (query (cdr path-and-query))
	 (frag (url-target obj)))
    (if user
	(setf (url-user obj) (url-hexify-string user)))
    (if pass
	(setf (url-password obj) (url-hexify-string pass)))
    (if path
	(setq path (url-hexify-string path url-path-allowed-chars)))
    (if query
	(setq query (url-hexify-string query url-query-allowed-chars)))
    (setf (url-filename obj) (if query (concat path "?" query) path))

    (if frag
	(setf (url-target obj)
	      (url-hexify-string frag url-query-allowed-chars)))
    (url-recreate-url obj)))