From f68c386341b86e68ff3157638bd8acd499a8ae1b Mon Sep 17 00:00:00 2001 From: Thomas Desveaux Date: Thu, 11 Oct 2018 14:21:42 +0200 Subject: [PATCH] path.normalize: Fix when call with path surrounded with quotes --- src/host/path_normalize.c | 13 +++++++++++-- tests/base/test_path.lua | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/host/path_normalize.c b/src/host/path_normalize.c index f754d32df9..62b141f4d6 100644 --- a/src/host/path_normalize.c +++ b/src/host/path_normalize.c @@ -9,6 +9,7 @@ #include #define IS_SEP(__c) ((__c) == '/' || (__c) == '\\') +#define IS_QUOTE(__c) ((__c) == '\"' || (__c) == '\'') #define IS_UPPER_ALPHA(__c) ((__c) >= 'A' && (__c) <= 'Z') #define IS_LOWER_ALPHA(__c) ((__c) >= 'a' && (__c) <= 'z') @@ -16,8 +17,8 @@ #define IS_SPACE(__c) ((__c >= '\t' && __c <= '\r') || __c == ' ') -static void* normalize_substring(const char* srcPtr, const char* srcEnd, char* dstPtr) { - +static void* normalize_substring(const char* srcPtr, const char* srcEnd, char* dstPtr) +{ #define IS_END(__p) (__p >= srcEnd || *__p == '\0') #define IS_SEP_OR_END(__p) (IS_END(__p) || IS_SEP(*__p)) @@ -114,6 +115,14 @@ int path_normalize(lua_State* L) while (*endPtr && !IS_SPACE(*endPtr)) ++endPtr; + // path is surrounded with quotes + if (readPtr != endPtr && + IS_QUOTE(*readPtr) && IS_QUOTE(endPtr[-1]) && + *readPtr == endPtr[-1]) + { + *(writePtr++) = *(readPtr++); + } + writePtr = normalize_substring(readPtr, endPtr, writePtr); // skip any white spaces between sub paths diff --git a/tests/base/test_path.lua b/tests/base/test_path.lua index d5d8290188..2de9438aa5 100755 --- a/tests/base/test_path.lua +++ b/tests/base/test_path.lua @@ -719,3 +719,8 @@ test.isequal("//myawesomeserver/test", path.normalize("//myawesomeserver/test/")) test.isequal("//myawesomeserver/test", path.normalize("///myawesomeserver/test/")) end + + function suite.normalize_quotedpath() + test.isequal("\"../../test/test/\"", path.normalize("\"../../test/test/\"")) + test.isequal("\"../../test/\"", path.normalize("\"../../test/../test/\"")) + end