* Documentation for uri.scm finished (except for resolve-uri-procedure as I can't figure out what this procedure is intended to do; someone out there who want to let me know?)
* new simplify-uri-path written (as the old one did not seem to work correctly)
This commit is contained in:
parent
5a15d24738
commit
812784c6bf
62
uri.scm
62
uri.scm
|
@ -103,7 +103,7 @@
|
||||||
; length of the
|
; length of the
|
||||||
; unescaped
|
; unescaped
|
||||||
; string
|
; string
|
||||||
(ns (make-string nlen))) ; the result
|
(ns (make-string nlen))) ; stores the result
|
||||||
|
|
||||||
(let lp ((i start) (j 0)) ; sweap over the string
|
(let lp ((i start) (j 0)) ; sweap over the string
|
||||||
(if (< j nlen)
|
(if (< j nlen)
|
||||||
|
@ -258,33 +258,35 @@
|
||||||
(join-strings plist "/")) ; Insert slashes between elts of PLIST.
|
(join-strings plist "/")) ; Insert slashes between elts of PLIST.
|
||||||
|
|
||||||
|
|
||||||
;;; Remove . and foo/.. elts from path. After simplification, there are no
|
;;; Remove . and <segment>/.. elements from path. The result is a
|
||||||
;;; . elements, and the only .. elements occur at the beginning of the path
|
;;; (maybe empty) list representing a path that does not contain "."
|
||||||
;;; (i.e., they attempt to back up past root). One could argue that this is
|
;;; and ".." elements neither at the beginning nor somewhere else. I
|
||||||
;;; illegal, and we should error out in this case, reporting an unresolvable
|
;;; tried to follow RFC2396 here. The procedure returns #f if the path
|
||||||
;;; URL. The URI "spec" is not even slightly clear on this issue.
|
;;; tries to back up past root (like "//.." or "/foo/../.."). "//" may
|
||||||
;;;
|
;;; occur somewhere in the path but not being backed up. Usually,
|
||||||
;;; URI's are pathetic. The case of /a/b//../c is ambiguous. Do we
|
;;; relative paths are intended to be used with a base
|
||||||
;;; 1) not simplify across multi-slashes?
|
;;; url. Accordingly to RFC2396 (as I hope) relative paths are
|
||||||
;;; 2) Flush the "empty" dir, giving /a/b//c
|
;;; considered not to start with "/". They are appended to a base
|
||||||
;;; 3) Flush across multi-slashes, giving /a/c
|
;;; URL-path and then simplified. So before you start to simplify a
|
||||||
;;; What is the meaning of //../a ? /../b ? /../../c ?
|
;;; URL try to find out if it is a relative path (i.e. it does not
|
||||||
|
;;; start with a "/").
|
||||||
|
|
||||||
|
(define (simplify-uri-path p)
|
||||||
|
(if (null? p) #f ; P must be non-null
|
||||||
|
(let lp ((path-list (cdr p))
|
||||||
|
(stack (list (car p))))
|
||||||
|
(if (null? path-list) ; we're done
|
||||||
|
(reverse stack)
|
||||||
|
(cond
|
||||||
|
((string=? (car path-list) "..") ; back up
|
||||||
|
; neither the empty path nor root
|
||||||
|
(if (not (or (null? stack) (string=? (car stack) "")))
|
||||||
|
(lp (cdr path-list) (cdr stack))
|
||||||
|
#f))
|
||||||
|
((string=? (car path-list) ".") ; leave this
|
||||||
|
(lp (cdr path-list) stack))
|
||||||
|
((string=? (car path-list) "") ; back to root
|
||||||
|
(lp (cdr path-list) '("")))
|
||||||
|
(else ; usual segment
|
||||||
|
(lp (cdr path-list) (cons (car path-list) stack))))))))
|
||||||
|
|
||||||
(define (simplify-uri-path p) ; P must be non-null.
|
|
||||||
(reverse (let lp ((path-list p)
|
|
||||||
(ans '()))
|
|
||||||
(let ((elt (car path-list))
|
|
||||||
(path-list (cdr path-list)))
|
|
||||||
(? ((pair? path-list)
|
|
||||||
(? ((string=? "." elt) ; Kill .
|
|
||||||
(lp path-list ans))
|
|
||||||
((string=? ".." elt)
|
|
||||||
(if (pair? ans)
|
|
||||||
(lp path-list (cddr ans))
|
|
||||||
(lp path-list (cons elt ans))))
|
|
||||||
(else
|
|
||||||
(lp path-list (cons elt ans)))))
|
|
||||||
;; Last element of list.
|
|
||||||
((string=? ".." elt)
|
|
||||||
(if (null? ans) '("..") (cddr ans)))
|
|
||||||
(else (cons elt ans)))))))
|
|
||||||
|
|
Loading…
Reference in New Issue