make-path should preserve a path containing just "/"

This commit is contained in:
Alex Shinn 2014-02-12 08:14:33 +09:00
parent 9651f7456c
commit 90dbe1fdd2
2 changed files with 11 additions and 2 deletions

View file

@ -216,12 +216,15 @@
(substring-cursor s 0 (string-skip-right s #\/))) (substring-cursor s 0 (string-skip-right s #\/)))
(if (null? args) (if (null? args)
"" ""
(let ((start (trim-trailing-slash (x->string (car args))))) (let* ((args0 (x->string (car args)))
(start (trim-trailing-slash args0)))
(let lp ((ls (cdr args)) (let lp ((ls (cdr args))
(res (if (string=? "" start) '() (list start)))) (res (if (string=? "" start) '() (list start))))
(cond (cond
((null? ls) ((null? ls)
(string-join (reverse res))) (if (and (null? res) (not (string=? "" args0)))
"/"
(string-join (reverse res))))
((pair? (car ls)) ((pair? (car ls))
(lp (append (car ls) (cdr ls)) res)) (lp (append (car ls) (cdr ls)) res))
(else (else

View file

@ -194,5 +194,11 @@
(test "a/b/./c" (make-path "a" "b" "." "c")) (test "a/b/./c" (make-path "a" "b" "." "c"))
(test "a/b/../c" (make-path "a" "b" ".." "c")) (test "a/b/../c" (make-path "a" "b" ".." "c"))
(test "a/b/c" (make-path "a" '("b" "c"))) (test "a/b/c" (make-path "a" '("b" "c")))
(test "/" (make-path "/" ""))
(test "/" (make-path "/" "/"))
(test "/." (make-path "/" "."))
(test "/a" (make-path "/a" ""))
(test "/a" (make-path "/a" "/"))
(test "/a/." (make-path "/a" "."))
(test-end) (test-end)