From 7b1613b5cfd5f75d719c91431ebcedb83dc675f0 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 25 Jul 2023 18:17:55 -0700 Subject: rel-path: treat empty paths as relative. * stdlib/path-test.tl (path-volume): Don't return :abs for a path whose empty first component isn't followed by any more items. Otherwise we return :abs for a path formed by splitting the empty string, and then calls like (rel-path "" "a") complain about a mixture of absolute and relative. With this change, empty paths given to rel-path behave as if they were ".". * tests/018/rel-path.tl: New test cases. --- stdlib/path-test.tl | 8 ++++---- tests/018/rel-path.tl | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/stdlib/path-test.tl b/stdlib/path-test.tl index 491f63af..b7e75018 100644 --- a/stdlib/path-test.tl +++ b/stdlib/path-test.tl @@ -301,9 +301,9 @@ (let ((vol (car more))) (cond ((nequal "" vol) - (set (car comp) "") - (set (cdr comp) (cdr more)) - vol) + (set (car comp) "") + (set (cdr comp) (cdr more)) + vol) (t :abs)))) ((and (m^ #/[A-Za-z0-9]+:/ head) head) (set (car comp) next) @@ -311,7 +311,7 @@ (if (and (equal "" next) more) ^(:abs . ,head) ^(:rel . ,head))))) - (if (equal head "") :abs)))) + (if (and (equal head "") (cdr comp)) :abs)))) (defun rel-path (from to) (let* ((fspl (path-split from)) diff --git a/tests/018/rel-path.tl b/tests/018/rel-path.tl index cdcc7e4f..11651c17 100644 --- a/tests/018/rel-path.tl +++ b/tests/018/rel-path.tl @@ -19,4 +19,7 @@ (rel-path "x///" "x") "." (rel-path "x" "x///") "." (rel-path "///x" "/x") "." - (rel-path "../../x" "y") :error) + (rel-path "../../x" "y") :error + (rel-path "" "") "." + (rel-path "a" "") ".." + (rel-path "" "a") "a") -- cgit v1.2.3