diff --git a/test_path.lua b/test_path.lua index 321c2ce..1128aca 100644 --- a/test_path.lua +++ b/test_path.lua @@ -142,6 +142,12 @@ function test_join_windows() assert_join_windows({'c:a/b', 'C:x/y'}, 'C:a/b\\x/y') assert_join_windows({'c:/', 'C:x/y'}, 'C:/x/y') assert_join_windows({'c:/a/b', 'C:x/y'}, 'C:/a/b\\x/y') + + for _, x in ipairs({'', 'a/b', '/a/b', 'c:', 'c:a/b', 'c:/', 'c:/a/b'}) do + for _, y in ipairs({'d:', 'd:x/y', 'd:/', 'd:/x/y'}) do + assert_join_windows({x, y}, y) + end + end end test_join_posix() diff --git a/z.lua b/z.lua index bce3248..0fc22c4 100755 --- a/z.lua +++ b/z.lua @@ -542,14 +542,8 @@ function os.path.join(path1, path2) end return path2 elseif windows then - local d1 = path1:sub(1, 2) - local d2 = path2:sub(1, 2) - if not path1:match('^%a:') then - d1 = '' - end - if not path2:match('^%a:') then - d2 = '' - end + local d1 = path1:match('^%a:') and path1:sub(1, 2) or '' + local d2 = path2:match('^%a:') and path2:sub(1, 2) or '' if d1 ~= '' then if d2 ~= '' then if d1:lower() == d2:lower() then @@ -558,6 +552,8 @@ function os.path.join(path1, path2) return path2 end end + elseif d2 ~= '' then + return path2 end end local postsep = true