Function: url-expander-remove-relative-links

url-expander-remove-relative-links is a byte-compiled function defined in url-expand.el.gz.

Signature

(url-expander-remove-relative-links NAME)

Source Code

;; Defined in /usr/src/emacs/lisp/url/url-expand.el.gz
(defun url-expander-remove-relative-links (name)
  (if (equal name "")
      ;; An empty name is a properly valid relative URL reference/path.
      ""
    ;; Strip . and .. from pathnames
    (let ((new (if (not (string-match "^/" name))
                   (concat "/" name)
                 name)))

      ;; If it ends with a '/.' or '/..', tack on a trailing '/' sot hat
      ;; the tests that follow are not too complicated in terms of
      ;; looking for '..' or '../', etc.
      (if (string-match "/\\.+$" new)
          (setq new (concat new "/")))

      ;; Remove '/./' first
      (while (string-match "/\\(\\./\\)" new)
        (setq new (concat (substring new 0 (match-beginning 1))
                          (substring new (match-end 1)))))

      ;; Then remove '/../'
      (while (string-match "/\\([^/]*/\\.\\./\\)" new)
        (setq new (concat (substring new 0 (match-beginning 1))
                          (substring new (match-end 1)))))

      ;; Remove cruft at the beginning of the string, so people that put
      ;; in extraneous '..' because they are morons won't lose.
      (while (string-match "^/\\.\\.\\(/\\)" new)
        (setq new (substring new (match-beginning 1) nil)))
      new)))