diff --git a/src/host/path_getrelative.c b/src/host/path_getrelative.c index b251eb3f..e08f3d4c 100644 --- a/src/host/path_getrelative.c +++ b/src/host/path_getrelative.c @@ -38,6 +38,11 @@ static void normalize(char* buffer, const char* path) ++src; } + /* remove any trailing slashes */ + for (--src; src > buffer && *src == '/'; --src) { + *src = '\0'; + } + *dst = '\0'; } diff --git a/tests/base/test_path.lua b/tests/base/test_path.lua index 4f31951b..fa1e2306 100755 --- a/tests/base/test_path.lua +++ b/tests/base/test_path.lua @@ -209,6 +209,10 @@ test.isequal("..", path.getrelative("/a///b/c","/a/b")) end + function suite.ignoresTrailingSlashes() + test.isequal("c", path.getrelative("/a/b/","/a/b/c")) + end + -- -- path.isabsolute() tests