123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- (require 'url-methods)
- (require 'url-util)
- (require 'url-parse)
- (eval-when-compile (require 'cl))
- (defun url-expander-remove-relative-links (name)
-
- (let ((new (if (not (string-match "^/" name))
- (concat "/" name)
- name)))
-
-
-
- (if (string-match "/\\.+$" new)
- (setq new (concat new "/")))
-
- (while (string-match "/\\(\\./\\)" new)
- (setq new (concat (substring new 0 (match-beginning 1))
- (substring new (match-end 1)))))
-
- (while (string-match "/\\([^/]*/\\.\\./\\)" new)
- (setq new (concat (substring new 0 (match-beginning 1))
- (substring new (match-end 1)))))
-
-
- (while (string-match "^/\\.\\.\\(/\\)" new)
- (setq new (substring new (match-beginning 1) nil)))
- new))
- (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)))
-
-
- (setq url (mapconcat (function (lambda (x)
- (if (memq x '(? ?\n ?\r))
- ""
- (char-to-string x))))
- url "")))
-
- (setq default (cond
- ((vectorp default)
-
- default)
- (default
-
- (url-generic-parse-url default))
- (url-current-object
-
- url-current-object)
- ((string-match url-nonrelative-link url)
-
- nil)
- (t
-
- (error "url-expand-file-name confused - no default?"))))
- (cond
- ((= (length url) 0)
- (url-recreate-url default))
- ((string-match "^#" url)
- url)
- ((string-match url-nonrelative-link url)
- url)
- (t
- (let* ((urlobj (url-generic-parse-url url))
- (inhibit-file-name-handlers t)
- (expander (url-scheme-get-property (url-type default) 'expand-file-name)))
- (if (string-match "^//" url)
- (setq urlobj (url-generic-parse-url (concat (url-type default) ":"
- url))))
- (funcall expander urlobj default)
- (url-recreate-url urlobj)))))
- (defun url-identity-expander (urlobj defobj)
- (setf (url-type urlobj) (or (url-type urlobj) (url-type defobj))))
- (defun url-default-expander (urlobj defobj)
-
- (if (url-type urlobj)
-
- nil
- (setf (url-type urlobj) (or (url-type urlobj) (url-type defobj)))
- (setf (url-port urlobj) (or (url-port urlobj)
- (and (string= (url-type urlobj)
- (url-type defobj))
- (url-port defobj))))
- (if (not (string= "file" (url-type urlobj)))
- (setf (url-host urlobj) (or (url-host urlobj) (url-host defobj))))
- (if (string= "ftp" (url-type urlobj))
- (setf (url-user urlobj) (or (url-user urlobj) (url-user defobj))))
- (if (string= (url-filename urlobj) "")
- (setf (url-filename urlobj) "/"))
- (if (string-match "^/" (url-filename urlobj))
- nil
- (let ((query nil)
- (file nil)
- (sepchar nil))
- (if (string-match "[?#]" (url-filename urlobj))
- (setq query (substring (url-filename urlobj) (match-end 0))
- file (substring (url-filename urlobj) 0 (match-beginning 0))
- sepchar (substring (url-filename urlobj) (match-beginning 0) (match-end 0)))
- (setq file (url-filename urlobj)))
-
-
-
- (setq file (url-expander-remove-relative-links
- (concat (url-file-directory (url-filename defobj)) file)))
- (setf (url-filename urlobj)
- (if query (concat file sepchar query) file))))))
- (provide 'url-expand)
|