Merge pull request #1176 from tdesveauxPKFX/host/fix_normalize

path.normalize: Fix when call with path surrounded with quotes
This commit is contained in:
Samuel Surtees 2018-10-12 11:01:16 +10:00 committed by GitHub
commit ea1df508bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -9,6 +9,7 @@
#include <string.h>
#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

View File

@ -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