Function: verb--clean-url
verb--clean-url is a natively compiled function defined in verb.el.
Signature
(verb--clean-url URL)
Documentation
Return a correctly encoded URL struct to use with url-retrieve.
Additionally, given a URL like "http://foo.com?a=b", return
"http://foo.com/?a=b". This is what curl does when the path is empty
and there are query string arguments present.
Also, replace any present Org hyperlinks with their literal link
contents, using verb-util--remove-org-hyperlinks.
If a scheme is not present, interpret the URL as a path, query string and fragment component of a URL with no host or scheme defined.
Source Code
;; Defined in /nix/store/8jnfn8w2mxcxbr2crbklcnija9m0zlkq-emacs-packages-deps/share/emacs/site-lisp/elpa/verb-20260818.1921/verb.el
(defun verb--clean-url (url)
"Return a correctly encoded URL struct to use with `url-retrieve'.
Additionally, given a URL like \"http://foo.com?a=b\", return
\"http://foo.com/?a=b\". This is what curl does when the path is empty
and there are query string arguments present.
Also, replace any present Org hyperlinks with their literal link
contents, using `verb-util--remove-org-hyperlinks'.
If a scheme is not present, interpret the URL as a path, query string
and fragment component of a URL with no host or scheme defined."
(let* ((url (verb-util--remove-org-hyperlinks url))
;; If we're not expanding code tags, do not attempt to encode
;; '{', '}', etc., so that we keep the original URL text.
(encoded-url (if verb--inhibit-code-tags-evaluation
url
(url-encode-url url)))
(url-obj (url-generic-parse-url encoded-url))
(path (url-filename url-obj))
(scheme (url-type url-obj)))
(if (not scheme)
;; If no scheme defined, interpret everything as path + query
;; string + fragment.
(progn
(setf (url-filename url-obj)
(concat (url-host url-obj)
(url-filename url-obj)))
(setf (url-host url-obj) nil))
;; Scheme is present:
(unless (member scheme '("http" "https"))
(user-error (concat "The URL must specify \"http://\" or "
"\"https://\" (got: \"%s\")")
scheme))
;; If path is "" but there are query string arguments, set path
;; to "/" (taken from curl).
;; Note that `path' here contains path and query string.
(when (string-prefix-p "?" path)
(setf (url-filename url-obj) (concat "/" path))))
url-obj))