From 90dbe1fdd2ae96027a310377c582d343043eed93 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Wed, 12 Feb 2014 08:14:33 +0900 Subject: [PATCH] make-path should preserve a path containing just "/" --- lib/chibi/pathname.scm | 7 +++++-- tests/path-tests.scm | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/chibi/pathname.scm b/lib/chibi/pathname.scm index 7da032f7..adcf6b8e 100644 --- a/lib/chibi/pathname.scm +++ b/lib/chibi/pathname.scm @@ -216,12 +216,15 @@ (substring-cursor s 0 (string-skip-right s #\/))) (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)) (res (if (string=? "" start) '() (list start)))) (cond ((null? ls) - (string-join (reverse res))) + (if (and (null? res) (not (string=? "" args0))) + "/" + (string-join (reverse res)))) ((pair? (car ls)) (lp (append (car ls) (cdr ls)) res)) (else diff --git a/tests/path-tests.scm b/tests/path-tests.scm index 25b98961..8d6aa422 100644 --- a/tests/path-tests.scm +++ b/tests/path-tests.scm @@ -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 "/" (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)