Function: url-expand-file-name
url-expand-file-name is an autoloaded and byte-compiled function
defined in url-expand.el.gz.
Signature
(url-expand-file-name URL &optional DEFAULT)
Documentation
Convert URL to a fully specified URL, and canonicalize it.
Second arg DEFAULT is a URL to start with if URL is relative.
If DEFAULT is nil or missing, the current buffer's URL is used.
Path components that are . are removed, and
path components followed by .. are removed, along with the .. itself.
Source Code
;; Defined in /usr/src/emacs/lisp/url/url-expand.el.gz
(defun url-expand-file-name (url &optional default)
"Convert URL to a fully specified URL, and canonicalize it.
Second arg DEFAULT is a URL to start with if URL is relative.
If DEFAULT is nil or missing, the current buffer's URL is used.
Path components that are `.' are removed, and
path components followed by `..' are removed, along with the `..' itself."
(if (and url (not (string-match "^#" url)))
;; Need to nuke newlines and spaces in the URL, or we open
;; ourselves up to potential security holes.
(setq url (mapconcat (lambda (x)
(if (memq x '(?\s ?\n ?\r))
""
(char-to-string x)))
url "")))
;; Need to figure out how/where to expand the fragment relative to
(setq default (cond
((url-p default)
;; Default URL has already been parsed
default)
(default
;; They gave us a default URL in non-parsed format
(url-generic-parse-url default))
(url-current-object
;; We are in a URL-based buffer, use the pre-parsed object
url-current-object)
((string-match url-nonrelative-link url)
;; The URL they gave us is absolute, go for it.
nil)
(t
;; Hmmm - this shouldn't ever happen.
(error "url-expand-file-name confused - no default?"))))
(cond
((= (length url) 0) ; nil or empty string
(url-recreate-url default))
((string-match url-nonrelative-link url) ; Fully-qualified URL,
; return it immediately
url)
(t
(let* ((urlobj (url-generic-parse-url url))
(inhibit-file-name-handlers t)
(expander (if (url-type default)
(url-scheme-get-property (url-type default)
'expand-file-name)
;; If neither the default nor the URL to be
;; expanded have a protocol, then just use the
;; identity expander as a fallback.
'url-identity-expander)))
(if (string-match "^//" url)
(setq urlobj (url-generic-parse-url (concat (url-type default) ":"
url))))
(funcall expander urlobj default)
(url-recreate-url urlobj)))))