From 15ceabac489275d4dba2f320ca0b6aaa3a76a031 Mon Sep 17 00:00:00 2001 From: Lusito Date: Sat, 1 Aug 2015 21:10:02 +0200 Subject: [PATCH] fix for path.join problem when both string start with a "..", a unit test has been added --- src/host/path_join.c | 4 ++++ tests/base/test_path.lua | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/host/path_join.c b/src/host/path_join.c index b4c02fdb..41663b17 100644 --- a/src/host/path_join.c +++ b/src/host/path_join.c @@ -71,6 +71,10 @@ int path_join(lua_State* L) break; } + if (start[0] == '.' && start[1] == '.' && start[2] == '\0'){ + break; + } + /* otherwise trim segment and the ".." sequence */ if (start != buffer) { --start; diff --git a/tests/base/test_path.lua b/tests/base/test_path.lua index ae072ee7..7d9883a3 100755 --- a/tests/base/test_path.lua +++ b/tests/base/test_path.lua @@ -267,6 +267,10 @@ test.isequal("", path.join("p1/p2/", "../..")) end + function suite.join_OnBothUpTwoFolders() + test.isequal("../../../../foo", path.join("../../", "../../foo")) + end + function suite.join_OnUptwoFolders() test.isequal("p1/foo", path.join("p1/p2/p3", "../../foo")) end