From 614cea1c98421d97a9553dac4a81e56fc0148ef8 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Wed, 8 Apr 2015 18:01:43 -0400 Subject: [PATCH] Fix handling of "../../.." sequences in path.normalize() --- src/host/path_normalize.c | 6 ++---- tests/base/test_path.lua | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/host/path_normalize.c b/src/host/path_normalize.c index 47de06fd..357bfdcf 100644 --- a/src/host/path_normalize.c +++ b/src/host/path_normalize.c @@ -35,13 +35,11 @@ int path_normalize(lua_State* L) if (ch == '.' && last == '.') { ptr = dst - 3; while (ptr >= buffer) { - if (*ptr != '/') { - --ptr; - } - else { + if (ptr[0] == '/' && ptr[1] != '.' && ptr[2] != '.') { dst = ptr; break; } + --ptr; } if (ptr >= buffer) { ++src; diff --git a/tests/base/test_path.lua b/tests/base/test_path.lua index cd3e7664..49abae88 100755 --- a/tests/base/test_path.lua +++ b/tests/base/test_path.lua @@ -385,6 +385,21 @@ test.isequal("../../test", p) end + function suite.normalize_Test4() + local p = path.normalize("../../../test/*.h") + test.isequal("../../../test/*.h", p) + end + + function suite.normalize_trailingDots1() + local p = path.normalize("../game/test/..") + test.isequal("../game", p) + end + + function suite.normalize_trailingDots2() + local p = path.normalize("../game/..") + test.isequal("..", p) + end + function suite.normalize() test.isequal("d:/ProjectB/bin", path.normalize("d:/ProjectA/../ProjectB/bin")) test.isequal("/ProjectB/bin", path.normalize("/ProjectA/../ProjectB/bin"))