diff options
-rw-r--r-- | jim-file.c | 13 | ||||
-rw-r--r-- | tests/filejoin.test | 18 |
2 files changed, 29 insertions, 2 deletions
@@ -285,9 +285,18 @@ static int file_cmd_join(Jim_Interp *interp, int argc, Jim_Obj *const *argv) last = newname; } #endif + else if (part[0] == '.') { + if (part[1] == '/') { + part += 2; + } + else if (part[1] == 0 && last != newname) { + /* Adding '.' to an existing path does nothing */ + continue; + } + } /* Add a slash if needed */ - if (last != newname) { + if (last != newname && last[-1] != '/') { *last++ = '/'; } @@ -302,7 +311,7 @@ static int file_cmd_join(Jim_Interp *interp, int argc, Jim_Obj *const *argv) } /* Remove a slash if needed */ - if (last != newname && last[-1] == '/') { + if (last > newname + 1 && last[-1] == '/') { *--last = 0; } } diff --git a/tests/filejoin.test b/tests/filejoin.test index 0cf1e03..7245938 100644 --- a/tests/filejoin.test +++ b/tests/filejoin.test @@ -50,6 +50,24 @@ test join-1.12 "Two names with double slashes" { file join abc/ /def } {/def} +test join-1.13 "Join to root" { + file join / abc +} {/abc} + +test join-1.14 "Join to root" { + set dir [file join / .] + # Either / or /. is OK here + expr {$dir in {/ /.}} +} 1 + +test join-1.15 "Join to root" { + file join / / +} {/} + +test join-1.16 "Join to root" { + file join /abc / +} {/} + test join-2.1 "Dir is empty string" { file join "" def } {def} |