diff --git a/src/host/path_getrelative.c b/src/host/path_getrelative.c index e08f3d4c..68ef72a8 100644 --- a/src/host/path_getrelative.c +++ b/src/host/path_getrelative.c @@ -87,8 +87,9 @@ int path_getrelative(lua_State* L) ++i; } - /* if they have nothing in common return absolute path */ - if (last <= 0) { + /* if I end up with just the root of the filesystem, either a single + * slash (/) or a drive letter (c:) then return the absolute path. */ + if (last <= 0 || (last == 2 && src[1] == ':')) { dst[strlen(dst) - 1] = '\0'; lua_pushstring(L, dst); return 1; diff --git a/tests/base/test_path.lua b/tests/base/test_path.lua index fa1e2306..905f681f 100755 --- a/tests/base/test_path.lua +++ b/tests/base/test_path.lua @@ -201,18 +201,22 @@ test.isequal("/opt/include", path.getrelative("/home/me/src/project", "/opt/include")) end - function suite.ignoresExtraSlashes2() + function suite.getrelative_ignoresExtraSlashes2() test.isequal("..", path.getrelative("/a//b/c","/a/b")) end - function suite.ignoresExtraSlashes3() + function suite.getrelative_ignoresExtraSlashes3() test.isequal("..", path.getrelative("/a///b/c","/a/b")) end - function suite.ignoresTrailingSlashes() + function suite.getrelative_ignoresTrailingSlashes() test.isequal("c", path.getrelative("/a/b/","/a/b/c")) end + function suite.getrelative_returnsAbsPath_onContactWithFileSysRoot() + test.isequal("C:/Boost/Include", path.getrelative("C:/Code/MyApp", "C:/Boost/Include")) + end + -- -- path.isabsolute() tests