From 9039232548406dd4273cf4f18268abfe0fd7b930 Mon Sep 17 00:00:00 2001 From: Sam Surtees Date: Mon, 8 Jan 2018 03:21:55 +1000 Subject: [PATCH] Fixed a bug with normalizing paths that contain dot folders - Added additional tests --- src/host/path_normalize.c | 3 ++- tests/base/test_path.lua | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/host/path_normalize.c b/src/host/path_normalize.c index cf744bd4..d0ab3981 100644 --- a/src/host/path_normalize.c +++ b/src/host/path_normalize.c @@ -35,7 +35,8 @@ static void* normalize_substring(const char* str, const char* endPtr, char* writ ptr = writePtr - 3; while (ptr >= writeBegin) { - if (ptr[0] == '/' && ptr[1] != '.' && ptr[2] != '.') { + /* break on '/' except when it's '/../' */ + if (ptr[0] == '/' && !(ptr[1] == '.' && ptr[2] == '.' && ptr[3] == '/')) { writePtr -= writePtr - ptr; /* special fix for cases, when '..' is the last chars in path i.e. d:\game\.., this should be converted into d:\, diff --git a/tests/base/test_path.lua b/tests/base/test_path.lua index 1874a4c3..80ba6416 100755 --- a/tests/base/test_path.lua +++ b/tests/base/test_path.lua @@ -683,4 +683,13 @@ function suite.normalize_legitimateDots() test.isequal("d:/test/test..test", path.normalize("d:/test/test..test")) test.isequal("d:/test..test/test", path.normalize("d:/test..test/test")) + test.isequal("d:/test/.test", path.normalize("d:/test/.test")) + test.isequal("d:/.test", path.normalize("d:/test/../.test")) + test.isequal("d:/test", path.normalize("d:/test/.test/..")) + test.isequal("d:/test/..test", path.normalize("d:/test/..test")) + test.isequal("d:/..test", path.normalize("d:/test/../..test")) + test.isequal("d:/test", path.normalize("d:/test/..test/..")) + test.isequal("d:/test/.test", path.normalize("d:/test/..test/../.test")) + test.isequal("d:/test/..test/.test", path.normalize("d:/test/..test/test/../.test")) + test.isequal("d:/test", path.normalize("d:/test/..test/../.test/..")) end